Skip to content

Commit b8a843f

Browse files
sinchangJacksonTian
authored andcommitted
test: add service cache unit test
1 parent 56e5d29 commit b8a843f

File tree

3 files changed

+23
-4
lines changed

3 files changed

+23
-4
lines changed

test/app/service/cache.test.js

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
'use strict';
2+
3+
const { app, assert } = require('egg-mock/bootstrap');
4+
5+
describe('test/app/service/cache.test.js', () => {
6+
it('set value should ok', async () => {
7+
const ctx = app.mockContext();
8+
const result = await ctx.service.cache.setex('greet', 'hi', 300);
9+
assert(result === undefined);
10+
});
11+
12+
it('get value should ok', async () => {
13+
const ctx = app.mockContext();
14+
const result1 = await ctx.service.cache.get('greet');
15+
assert(result1 === 'hi');
16+
const result2 = await ctx.service.cache.get('greet123');
17+
assert(result2 === undefined);
18+
});
19+
});

test/app/service/mail.test.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
const { app } = require('egg-mock/bootstrap');
44

5-
describe('test/app/service/mail.js', () => {
5+
describe('test/app/service/mail.test.js', () => {
66
describe('sendActiveMail', () => {
77
it('should ok', async () => {
88
const ctx = app.mockContext();

test/app/service/topic.test.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -62,15 +62,15 @@ describe('test/app/service/topic.test.js', () => {
6262
good: false,
6363
};
6464
const result = await topic.getCountByQuery(query);
65-
assert(result === 1);
65+
assert(result >= 1);
6666
});
6767

6868
it('getTopicsByQuery should ok', async () => {
6969
const query1 = {
7070
good: false,
7171
};
7272
const result1 = await topic.getTopicsByQuery(query1, {});
73-
assert(result1.length === 1);
73+
assert(result1.length >= 1);
7474

7575
const query2 = {
7676
good: 'test',
@@ -81,7 +81,7 @@ describe('test/app/service/topic.test.js', () => {
8181

8282
it('getLimit5w should ok', async () => {
8383
const result = await topic.getLimit5w();
84-
assert(result.length === 1);
84+
assert(result.length >= 1);
8585
});
8686

8787
it('getFullTopic should ok', async () => {

0 commit comments

Comments
 (0)