|
@@ -0,0 +1,158 @@
|
|
|
+'use strict';
|
|
|
+
|
|
|
+const mock = require('egg-mock');
|
|
|
+const helper = require('../../app/extend/helper');
|
|
|
+
|
|
|
+describe('test/controller/comon.test.js', () => {
|
|
|
+ let app;
|
|
|
+ before(() => {
|
|
|
+ // 创建当前应用的 app 实例
|
|
|
+ app = mock.app();
|
|
|
+ // 等待 app 启动成功,才能执行测试用例
|
|
|
+ return app.ready();
|
|
|
+ });
|
|
|
+ afterEach(mock.restore);
|
|
|
+
|
|
|
+ describe('GET /report/user/index', () => {
|
|
|
+ it('should status 200 and get the body', () => {
|
|
|
+ const params = new URLSearchParams();
|
|
|
+ params.set('type', 0);
|
|
|
+ params.set('startTime', helper.mToday());
|
|
|
+ params.set('endTime', helper.today());
|
|
|
+ return app.httpRequest()
|
|
|
+ .get(`/report/user/index?${params.toString()}`)
|
|
|
+ .expect(200)
|
|
|
+ .expect(res => {
|
|
|
+ if (res.body.code != 0) throw new Error(res.body.msg);
|
|
|
+ });
|
|
|
+
|
|
|
+ });
|
|
|
+ it('should status 200 and get the body', () => {
|
|
|
+ const params = new URLSearchParams();
|
|
|
+ params.set('type', 1);
|
|
|
+ params.set('startTime', helper.yMonth());
|
|
|
+ params.set('endTime', helper.nextMonth());
|
|
|
+ return app.httpRequest()
|
|
|
+ .get(`/report/user/index?${params.toString()}`)
|
|
|
+ .expect(200)
|
|
|
+ .expect(res => {
|
|
|
+ if (res.body.code != 0) throw new Error(res.body.msg);
|
|
|
+ });
|
|
|
+
|
|
|
+ });
|
|
|
+ it('should status 200 and get the body', () => {
|
|
|
+ const params = new URLSearchParams();
|
|
|
+ params.set('type', 2);
|
|
|
+ params.set('startTime', helper.before3Year());
|
|
|
+ params.set('endTime', helper.nextYear());
|
|
|
+ return app.httpRequest()
|
|
|
+ .get(`/report/user/index?${params.toString()}`)
|
|
|
+ .expect(200)
|
|
|
+ .expect(res => {
|
|
|
+ if (res.body.code != 0) throw new Error(res.body.msg);
|
|
|
+ });
|
|
|
+ });
|
|
|
+ });
|
|
|
+ describe('GET /report/user/saled', () => {
|
|
|
+ it('should status 200 and get the body', () => {
|
|
|
+ const params = new URLSearchParams();
|
|
|
+ params.set('type', 0);
|
|
|
+ params.set('startTime', helper.mToday());
|
|
|
+ params.set('endTime', helper.today());
|
|
|
+ return app.httpRequest()
|
|
|
+ .get(`/report/user/saled?${params.toString()}`)
|
|
|
+ .expect(200)
|
|
|
+ .expect(res => {
|
|
|
+ if (res.body.code != 0) throw new Error(res.body.msg);
|
|
|
+ });
|
|
|
+
|
|
|
+ });
|
|
|
+ it('should status 200 and get the body', () => {
|
|
|
+ const params = new URLSearchParams();
|
|
|
+ params.set('type', 1);
|
|
|
+ params.set('startTime', helper.yMonth());
|
|
|
+ params.set('endTime', helper.nextMonth());
|
|
|
+ return app.httpRequest()
|
|
|
+ .get(`/report/user/saled?${params.toString()}`)
|
|
|
+ .expect(200)
|
|
|
+ .expect(res => {
|
|
|
+ if (res.body.code != 0) throw new Error(res.body.msg);
|
|
|
+ });
|
|
|
+
|
|
|
+ });
|
|
|
+ it('should status 200 and get the body', () => {
|
|
|
+ const params = new URLSearchParams();
|
|
|
+ params.set('type', 2);
|
|
|
+ params.set('startTime', helper.before3Year());
|
|
|
+ params.set('endTime', helper.nextYear());
|
|
|
+ return app.httpRequest()
|
|
|
+ .get(`/report/user/saled?${params.toString()}`)
|
|
|
+ .expect(200)
|
|
|
+ .expect(res => {
|
|
|
+ if (res.body.code != 0) throw new Error(res.body.msg);
|
|
|
+ });
|
|
|
+ });
|
|
|
+ });
|
|
|
+ describe('GET /report/user/saledExt', () => {
|
|
|
+ it('should status 200 and get the body', () => {
|
|
|
+ return app.httpRequest()
|
|
|
+ .get('/report/user/saledExt')
|
|
|
+ .expect(200)
|
|
|
+ .expect(res => {
|
|
|
+ if (res.body.code != 0) throw new Error(res.body.msg);
|
|
|
+ });
|
|
|
+ });
|
|
|
+ });
|
|
|
+ describe('GET /report/user/sexAndAge', () => {
|
|
|
+ it('should status 200 and get the body', () => {
|
|
|
+ return app.httpRequest()
|
|
|
+ .get('/report/user/sexAndAge')
|
|
|
+ .expect(200)
|
|
|
+ .expect(res => {
|
|
|
+ if (res.body.code != 0) throw new Error(res.body.msg);
|
|
|
+ });
|
|
|
+
|
|
|
+ });
|
|
|
+ });
|
|
|
+ describe('GET /report/user/register', () => {
|
|
|
+ it('should status 200 and get the body', () => {
|
|
|
+ const params = new URLSearchParams();
|
|
|
+ params.set('type', 0);
|
|
|
+ params.set('startTime', helper.mToday());
|
|
|
+ params.set('endTime', helper.today());
|
|
|
+ return app.httpRequest()
|
|
|
+ .get(`/report/user/register?${params.toString()}`)
|
|
|
+ .expect(200)
|
|
|
+ .expect(res => {
|
|
|
+ if (res.body.code != 0) throw new Error(res.body.msg);
|
|
|
+ });
|
|
|
+
|
|
|
+ });
|
|
|
+ it('should status 200 and get the body', () => {
|
|
|
+ const params = new URLSearchParams();
|
|
|
+ params.set('type', 1);
|
|
|
+ params.set('startTime', helper.yMonth());
|
|
|
+ params.set('endTime', helper.nextMonth());
|
|
|
+ return app.httpRequest()
|
|
|
+ .get(`/report/user/register?${params.toString()}`)
|
|
|
+ .expect(200)
|
|
|
+ .expect(res => {
|
|
|
+ if (res.body.code != 0) throw new Error(res.body.msg);
|
|
|
+ });
|
|
|
+
|
|
|
+ });
|
|
|
+ it('should status 200 and get the body', () => {
|
|
|
+ const params = new URLSearchParams();
|
|
|
+ params.set('type', 2);
|
|
|
+ params.set('startTime', helper.before3Year());
|
|
|
+ params.set('endTime', helper.nextYear());
|
|
|
+ return app.httpRequest()
|
|
|
+ .get(`/report/user/register?${params.toString()}`)
|
|
|
+ .expect(200)
|
|
|
+ .expect(res => {
|
|
|
+ if (res.body.code != 0) throw new Error(res.body.msg);
|
|
|
+ });
|
|
|
+ });
|
|
|
+ });
|
|
|
+
|
|
|
+});
|