You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
224 lines
8.2 KiB
224 lines
8.2 KiB
const request = require('supertest');
|
|
const expect = require('chai').expect;
|
|
const app = require('../Reject.js');
|
|
|
|
// 测试API端点
|
|
describe('API Endpoints', () => {
|
|
// 测试数据库连接
|
|
describe('GET /api/test-db', () => {
|
|
it('should return database connection status', async () => {
|
|
const res = await request(app)
|
|
.get('/api/test-db')
|
|
.set('Accept', 'application/json');
|
|
|
|
expect(res.status).to.equal(200);
|
|
expect(res.body).to.be.an('object');
|
|
expect(res.body).to.have.property('success');
|
|
});
|
|
});
|
|
|
|
// 测试获取货源列表
|
|
describe('GET /api/supplies', () => {
|
|
it('should return supplies list', async () => {
|
|
const res = await request(app)
|
|
.get('/api/supplies')
|
|
.set('Accept', 'application/json');
|
|
|
|
expect(res.status).to.equal(200);
|
|
expect(res.body).to.be.an('object');
|
|
expect(res.body).to.have.property('success');
|
|
expect(res.body).to.have.property('data');
|
|
});
|
|
});
|
|
|
|
// 测试获取供应商列表
|
|
describe('GET /api/suppliers', () => {
|
|
it('should return suppliers list', async () => {
|
|
const res = await request(app)
|
|
.get('/api/suppliers')
|
|
.set('Accept', 'application/json');
|
|
|
|
expect(res.status).to.equal(200);
|
|
expect(res.body).to.be.an('object');
|
|
expect(res.body).to.have.property('success');
|
|
expect(res.body).to.have.property('data');
|
|
});
|
|
});
|
|
|
|
// 测试获取联系人列表
|
|
describe('GET /api/contacts', () => {
|
|
it('should return contacts list', async () => {
|
|
const res = await request(app)
|
|
.get('/api/contacts')
|
|
.set('Accept', 'application/json');
|
|
|
|
expect(res.status).to.equal(200);
|
|
expect(res.body).to.be.an('object');
|
|
expect(res.body).to.have.property('success');
|
|
expect(res.body).to.have.property('data');
|
|
});
|
|
});
|
|
|
|
// 测试获取审核失败原因
|
|
describe('GET /api/supplies/:id/reject-reason', () => {
|
|
it('should return reject reason for supply', async () => {
|
|
// 首先获取一个货源ID
|
|
const suppliesRes = await request(app)
|
|
.get('/api/supplies')
|
|
.set('Accept', 'application/json');
|
|
|
|
if (suppliesRes.body.data && suppliesRes.body.data.length > 0) {
|
|
const supplyId = suppliesRes.body.data[0].id;
|
|
const res = await request(app)
|
|
.get(`/api/supplies/${supplyId}/reject-reason`)
|
|
.set('Accept', 'application/json');
|
|
|
|
expect(res.status).to.equal(200);
|
|
expect(res.body).to.be.an('object');
|
|
expect(res.body).to.have.property('success');
|
|
}
|
|
});
|
|
});
|
|
|
|
// 测试获取拒绝审核API路由注册
|
|
describe('GET /api/supplies/:id/reject', () => {
|
|
it('should return method not allowed for GET', async () => {
|
|
const res = await request(app)
|
|
.get('/api/supplies/1/reject')
|
|
.set('Accept', 'application/json');
|
|
|
|
expect(res.status).to.equal(405); // Method Not Allowed
|
|
});
|
|
});
|
|
|
|
// 测试获取供应商审核通过API路由注册
|
|
describe('GET /api/suppliers/:id/approve', () => {
|
|
it('should return method not allowed for GET', async () => {
|
|
const res = await request(app)
|
|
.get('/api/suppliers/1/approve')
|
|
.set('Accept', 'application/json');
|
|
|
|
expect(res.status).to.equal(405); // Method Not Allowed
|
|
});
|
|
});
|
|
|
|
// 测试获取供应商审核拒绝API路由注册
|
|
describe('GET /api/suppliers/:id/reject', () => {
|
|
it('should return method not allowed for GET', async () => {
|
|
const res = await request(app)
|
|
.get('/api/suppliers/1/reject')
|
|
.set('Accept', 'application/json');
|
|
|
|
expect(res.status).to.equal(405); // Method Not Allowed
|
|
});
|
|
});
|
|
|
|
// 测试获取供应商开始合作API路由注册
|
|
describe('GET /api/suppliers/:id/cooperate', () => {
|
|
it('should return method not allowed for GET', async () => {
|
|
const res = await request(app)
|
|
.get('/api/suppliers/1/cooperate')
|
|
.set('Accept', 'application/json');
|
|
|
|
expect(res.status).to.equal(405); // Method Not Allowed
|
|
});
|
|
});
|
|
|
|
// 测试获取供应商终止合作API路由注册
|
|
describe('GET /api/suppliers/:id/terminate', () => {
|
|
it('should return method not allowed for GET', async () => {
|
|
const res = await request(app)
|
|
.get('/api/suppliers/1/terminate')
|
|
.set('Accept', 'application/json');
|
|
|
|
expect(res.status).to.equal(405); // Method Not Allowed
|
|
});
|
|
});
|
|
|
|
// 测试获取创建货源API路由注册
|
|
describe('GET /api/supplies/create', () => {
|
|
it('should return method not allowed for GET', async () => {
|
|
const res = await request(app)
|
|
.get('/api/supplies/create')
|
|
.set('Accept', 'application/json');
|
|
|
|
expect(res.status).to.equal(405); // Method Not Allowed
|
|
});
|
|
});
|
|
|
|
// 测试获取图片上传API路由注册
|
|
describe('GET /api/upload-image', () => {
|
|
it('should return method not allowed for GET', async () => {
|
|
const res = await request(app)
|
|
.get('/api/upload-image')
|
|
.set('Accept', 'application/json');
|
|
|
|
expect(res.status).to.equal(405); // Method Not Allowed
|
|
});
|
|
});
|
|
|
|
// 测试获取下架货源API路由注册
|
|
describe('GET /api/supplies/:id/unpublish', () => {
|
|
it('should return method not allowed for GET', async () => {
|
|
const res = await request(app)
|
|
.get('/api/supplies/1/unpublish')
|
|
.set('Accept', 'application/json');
|
|
|
|
expect(res.status).to.equal(405); // Method Not Allowed
|
|
});
|
|
});
|
|
|
|
// 测试获取上架货源API路由注册
|
|
describe('GET /api/supplies/:id/publish', () => {
|
|
it('should return method not allowed for GET', async () => {
|
|
const res = await request(app)
|
|
.get('/api/supplies/1/publish')
|
|
.set('Accept', 'application/json');
|
|
|
|
expect(res.status).to.equal(405); // Method Not Allowed
|
|
});
|
|
});
|
|
|
|
// 测试获取删除货源API路由注册
|
|
describe('GET /api/supplies/:id/delete', () => {
|
|
it('should return method not allowed for GET', async () => {
|
|
const res = await request(app)
|
|
.get('/api/supplies/1/delete')
|
|
.set('Accept', 'application/json');
|
|
|
|
expect(res.status).to.equal(405); // Method Not Allowed
|
|
});
|
|
});
|
|
|
|
// 测试获取更新货源状态API路由注册
|
|
describe('GET /api/supplies/:id', () => {
|
|
it('should return method not allowed for GET', async () => {
|
|
const res = await request(app)
|
|
.get('/api/supplies/1')
|
|
.set('Accept', 'application/json');
|
|
|
|
expect(res.status).to.equal(405); // Method Not Allowed
|
|
});
|
|
});
|
|
|
|
// 测试获取编辑货源API路由注册
|
|
describe('GET /api/supplies/:id/edit', () => {
|
|
it('should return method not allowed for GET', async () => {
|
|
const res = await request(app)
|
|
.get('/api/supplies/1/edit')
|
|
.set('Accept', 'application/json');
|
|
|
|
expect(res.status).to.equal(405); // Method Not Allowed
|
|
});
|
|
});
|
|
});
|
|
|
|
// 测试服务器启动
|
|
describe('Server', () => {
|
|
it('should be listening on port 3000', () => {
|
|
// 这个测试主要验证app对象是否被正确导出
|
|
expect(app).to.be.an('object');
|
|
expect(app).to.have.property('listen');
|
|
expect(app.listen).to.be.a('function');
|
|
});
|
|
});
|
|
|