UNPKG

yapi-plugin-pl-auto-test

Version:

YAPI自动化测试插件,支持在YAPI设置测试计划,历史测试结果存入ES,界面显示测试结果,自定义通知。

93 lines (81 loc) 1.82 kB
const yapi = require('yapi.js'); const baseModel = require('models/base.js'); let mongoose = require('mongoose'); let Schema = mongoose.Schema; class testResultModel extends baseModel { getName () { return 'auto_test_result'; } getSchema () { return { uid: Number, project_id: { type: Number, required: true }, // 通过测试计划执行才有,没有则为-1 plan_id: { type: Number, default: -1 }, col_names: { type: Array, default: [] }, env: Array, add_time: Number, test_url: String, status: String, data: Schema.Types.Mixed }; } get (id) { return this.model.findOne({ _id: id }); } save (data) { data.add_time = yapi.commons.time(); const log = new this.model(data); return log.save(); } findByProject (id) { return this.model .find({ project_id: id }) .exec(); } findByPlan (id) { return this.model .find({ plan_id: id }) .sort({ _id: -1 }) .exec(); } // timeStart, int with second as unit <= ,> getTimeNewestMessage(colName, timeStart, timeEnd){ return this.model .findOne({ col_names: colName, add_time:{ $gte: timeStart, $lt: timeEnd} }) .select("data.message") .sort({ add_time: -1 }) .limit(1) .exec(); } del (id) { return this.model.remove({ _id: id }); } deleteByIds (ids) { return this.model.remove({ _id: { $in: ids } }); } deleteAll (plan_id) { return this.model.remove({ plan_id: plan_id }); } } module.exports = testResultModel;