UNPKG

yapi-plugin-intl-auto-test

Version:

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

124 lines (99 loc) 2.2 kB
const yapi = require('yapi.js'); const baseModel = require('models/base.js'); class testPlanModel extends baseModel { getName () { return 'auto_test_plan'; } getSchema () { return { uid: Number, // 项目id project_id: { type: Number, required: true }, // 计划名称 plan_name: { type: String, required: true }, //是否开启自动测试 is_plan_open: { type: Boolean, default: false }, //自动测试定时任务的cron表达式 plan_cron: String, //自动测试url plan_url: String, //保留多少次执行结果,为-1表示不限 plan_result_size: { type: Number, default: 10 }, notifier: { target: String, url: String }, notice_trigger: { type: String, enum: ["never", "any", "fail", "success", "part"] }, webhook: { type: Boolean, default: false }, webhook_url: String, webhook_status: String, webhook_data: String, //上次执行时间 last_test_time: { type: Number, default: null }, add_time: Number, up_time: Number }; } save (data) { data.add_time = yapi.commons.time(); data.up_time = yapi.commons.time(); const plan = new this.model(data); return plan.save(); } listAll () { return this.model .find() .sort({ _id: -1 }) .exec(); } find (id) { return this.model.findOne({ _id: id }); } findByName (name) { return this.model.findOne({ plan_name: name }); } findByProject (id) { return this.model .find({ project_id: id }) .sort({ _id: -1 }) .exec(); } update (id, data) { data.up_time = yapi.commons.time(); return this.model.update( { _id: id }, data ); } del (id) { return this.model.remove({ _id: id }); } } module.exports = testPlanModel;