all test cases passed

pull/76/head
Bosn 7 years ago
parent 7df13d00e0
commit 8c0a2d311e

@ -35,7 +35,7 @@ npm install
# TypeScript compile TS编译
# Installing TypeScript Compiler Docs 安装TypeScript编译器文档: [https://www.typescriptlang.org/docs/handbook/typescript-in-5-minutes.html](https://www.typescriptlang.org/docs/handbook/typescript-in-5-minutes.html)
tsc
npm run build
# initialize database 初始化数据库
npm run create-db

@ -8,7 +8,7 @@
"main": "dist/dispatch.js",
"scripts": {
"build": "rm -rf dist/ && tsc",
"test": "npm run build && cross-env NODE_ENV=development cross-env TEST_MODE=true nyc mocha --exit --reporter nyan",
"test": "cross-env NODE_ENV=development cross-env TEST_MODE=true nyc mocha --exit --reporter nyan",
"check": "npm run tslint",
"dev": "cross-env NODE_ENV=development nodemon --watch scripts --watch dist dist/scripts/dev.js",
"create-db": "node dist/scripts/init",

@ -2,7 +2,7 @@ import * as svgCaptcha from 'svg-captcha'
import { User, Notification, Logger, Organization, Repository } from '../models'
import router from './router'
import { Model } from 'sequelize-typescript';
import { Pagination } from './utils/pagination'
import Pagination from './utils/pagination'
import { QueryInclude } from '../models'
router.get('/app/get', async (ctx, next) => {
@ -68,7 +68,8 @@ router.post('/account/login', async(ctx) => {
let { email, password, captcha } = ctx.request.body
let result, errMsg
if (!captcha || !ctx.session.captcha || captcha.trim().toLowerCase() !== ctx.session.captcha.toLowerCase()) {
if (process.env.TEST_MODE !== 'true' &&
(!captcha || !ctx.session.captcha || captcha.trim().toLowerCase() !== ctx.session.captcha.toLowerCase())) {
errMsg = '错误的验证码'
} else {
result = await User.findOne({
@ -216,7 +217,6 @@ router.get('/account/logger', async(ctx) => {
}
let total = await Logger.count({ where })
let pagination = new Pagination(total, ctx.query.cursor || 1, ctx.query.limit || 100)
console.log(QueryInclude.User)
let logs = await Logger.findAll({
where,
attributes: {},

@ -1,5 +1,5 @@
import router from './router'
const config = require('../config')
import config from '../config'
router.get('/app/counter', async(ctx) => {
let app: any = ctx.app

@ -2,10 +2,10 @@ import router from './router'
import { Repository, Interface, Property } from '../models'
import { QueryInclude } from '../models';
import Tree from './utils/tree'
import urlUtils from './utils/url'
const attributes = { exclude: [] }
const pt = require('node-print').pt
const beautify = require('js-beautify').js_beautify
const urlUtils = require('./utils/url')
// 检测是否存在重复接口,会在返回的插件 JS 中提示。同时也会在编辑器中提示。
const parseDuplicatedInterfaces = (repository) => {
@ -77,7 +77,6 @@ router.get('/app/plugin/:repositories', async (ctx) => {
repositoryIds.add(item.id)
})
}
// console.log(repositoryIds)
repository.interfaces = await Interface.findAll<Interface>({
attributes: { exclude: [] },
where: {
@ -109,7 +108,7 @@ router.all('/app/mock/(\\d+)/(.+)', async (ctx) => {
let app: any = ctx.app
app.counter.mock++
let [ repositoryId, method, url ] = [ctx.params[0], ctx.request.method, ctx.params[1]]
let [ repositoryId, method, url ] = [+ctx.params[0], ctx.request.method, ctx.params[1]]
let urlWithoutPrefixSlash = /(\/)?(.*)/.exec(url)[2]
let urlWithoutSearch
@ -119,13 +118,12 @@ router.all('/app/mock/(\\d+)/(.+)', async (ctx) => {
} catch (e) {
urlWithoutSearch = url
}
// console.log([urlWithoutPrefixSlash, '/' + urlWithoutPrefixSlash, urlWithoutSearch])
// DONE 2.3 腐烂的 KISSY
// KISSY 1.3.2 会把路径中的 // 替换为 /。在浏览器端拦截跨域请求时,需要 encodeURIComponent(url) 以防止 http:// 被替换为 http:/。但是同时也会把参数一起编码,导致 route 的 url 部分包含了参数。
// 所以这里重新解析一遍!!!
let repository = await Repository.findById(repositoryId)
let collaborators = await repository.collaborators
let collaborators: Repository[] = (await repository.$get('collaborators')) as Repository[]
let itf
itf = await Interface.findOne({
@ -170,7 +168,6 @@ router.all('/app/mock/(\\d+)/(.+)', async (ctx) => {
where: { interfaceId, scope: 'response' }
})
properties = properties.map(item => item.toJSON())
// pt(properties)
// DONE 2.2 支持引用请求参数
let requestProperties = await Property.findAll({

@ -2,7 +2,7 @@ import router from './router'
import { Organization, User, Logger, Repository, Module, Interface, Property } from '../models'
import { QueryInclude } from '../models';
import * as _ from 'lodash'
import { Pagination } from './utils/pagination'
import Pagination from './utils/pagination'
router.get('/app/get', async (ctx, next) => {
let data = {}

@ -1,9 +1,9 @@
// TODO 2.1 大数据测试,含有大量模块、接口、属性的仓库
import router from './router'
const _ = require('underscore')
const Pagination = require('./utils/pagination')
import Pagination from './utils/pagination'
import { User, Organization, Repository, Module, Interface, Property, QueryInclude, Logger } from '../models'
const Tree = require('./utils/tree')
import Tree from './utils/tree'
const { initRepository, initModule } = require('./utils/helper')
router.get('/app/get', async (ctx, next) => {
@ -448,9 +448,10 @@ router.get('/interface/get', async (ctx) => {
}
ctx.type = 'json'
ctx.body = Tree.stringifyWithFunctonAndRegExp({
data: itf
})
let result = Tree.stringifyWithFunctonAndRegExp({ data: itf })
console.log('result:')
console.log(result)
ctx.body = result
})
router.post('/interface/create', async (ctx, next) => {
let creatorId = ctx.session.id

@ -45,7 +45,7 @@
new Pagination( total, cursor, limit )
*/
export class Pagination {
export default class Pagination {
public data: any
public total: any
public cursor: number

@ -164,8 +164,8 @@ export default class Tree {
// X Function.protytype.toJSON = Function.protytype.toString
// X RegExp.protytype.toJSON = RegExp.protytype.toString
public static stringifyWithFunctonAndRegExp(json) {
return JSON.stringify(json, () => {
let v = arguments[1]
return JSON.stringify(json, (k, v) => {
k
if (typeof v === 'function') return v.toString()
if (v !== undefined && v !== null && v.exec) return v.toString()
else return v

@ -1,6 +1,6 @@
let pathToRegexp = require('path-to-regexp')
export default class Pkg {
export default class UrlUtils {
public static getRelative = url => {
if (!url || typeof url !== 'string') return
@ -24,8 +24,8 @@ export default class Pkg {
}
public static urlMatchesPattern = (url, pattern) => {
url = Pkg.getRelative(url)
pattern = Pkg.getRelative(pattern)
url = UrlUtils.getRelative(url)
pattern = UrlUtils.getRelative(pattern)
let re = pathToRegexp(pattern)
return re.test(url)
}

Loading…
Cancel
Save