???????????API??????????
???????????? ???????[ 2017/1/9 10:22:42 ] ????????API??? ???????
??????????У???????????????????????????????????? jsdoc ?? swagger ??????????????????????????????д????????淶?????????????????????????????????????????????
??????????????????????????????????????????? API??????д????????????????????????????????????????????е???????????????? API ????????????????????д????????????????????????????????????? markdown ????????????????? Gitlab ?? wiki ?????????????????????? commit ?? history ????????汾??
???????????? API ?????д????????????????????????????????????????????????????????????????????????????????? API ?????????
????????????????????????? mocha ?? supertest ?? power-assert ??Web ???? express ??
?????????????????
// app.js
const express = require('express');
const bodyParser = require('body-parser');
const app = express();
app.use(bodyParser.json());
app.use(bodyParser.urlencoded({ extended: true }));
app.post('/user/create'?? function(req?? res){
const name = req.body.name;
res.json({
status: 200??
error_code: 0??
message: 'success'??
data: {
id: '123abc'??
name: 'node'??
gender: 'male'??
age: 23??
}??
});
});
app.get('/user/search'?? function(req?? res){
const name = req.query.name;
res.json({
status: 200??
error_code: 0??
message: 'success'??
data: {
id: '123abc'??
name: 'node'??
gender: 'male'??
age: 23??
}??
});
});
app.get('/user/:id'?? function(req?? res){
const userId = req.params.id;
res.json({
status: 200??
error_code: 0??
message: 'success'??
data: {
id: '123abc'??
name: 'node'??
gender: 'male'??
age: 23??
}??
});
});
app.listen(3000?? function(){
console.log(`Server is listening on 3000`);
});
module.exports = app;
??????????????????
// test/uset.test.js
const assert = require('power-assert');
const supertest = require('supertest');
const U = require('../utils');
const app = require('../app');
const agent = supertest.agent(app);
describe('Test'?? function(){
it('should create user success'?? function(done){
U.test({
agent??
file: 'user'??
group: '??????API'??
title: '???????'??
method: 'post'??
url: '/user/create'
params: {
name: { value: 'node'?? type: 'String'?? required: true?? desc: '????' }??
gender: { value: 'male'?? type: 'String'?? required: false?? desc: '???' }??
age: { value: 23?? type: 'Int'?? required: false?? desc: '' }??
}??
headers: { entrance: 'client' }??
expect: 200??
callback (err?? res) {
if (err) return done(err);
assert(res.body.data.name === 'node');
assert(res.body.data.age === 23);
done();
}??
});
});
it('should search user success'?? function(done){
U.test({
agent??
file: 'user'??
group: '??????API'??
title: '???????'??
method: 'get'??
url: '/user/search'
params: {
name: { value: 'node'?? type: 'String'?? required: true?? desc: '????' }??
}??
expect: 200??
callback (err?? res) {
if (err) return done(err);
assert(res.body.data.name === 'node');
assert(res.body.data.age === 23);
done();
}??
});
});
it('should search user success'?? function(done){
U.test({
agent??
file: 'user'??
group: '??????API'??
title: '?????????'??
method: 'get'??
url: '/user/:id'
params: {
id: { value: '123abc'?? type: 'String'?? required: true?? desc: '' }??
}??
expect: 200??
callback (err?? res) {
if (err) return done(err);
assert(res.body.data.name === 'node');
assert(res.body.data.age === 23);
done();
}??
});
});
});
??????
???·???
??????????????????
2023/3/23 14:23:39???д?ò??????????
2023/3/22 16:17:39????????????????????Щ??
2022/6/14 16:14:27??????????????????????????
2021/10/18 15:37:44???????????????
2021/9/17 15:19:29???·???????·
2021/9/14 15:42:25?????????????
2021/5/28 17:25:47??????APP??????????
2021/5/8 17:01:11