Skip to content

Commit 64ce901

Browse files
committed
update apikey unit test
1 parent 22a5d97 commit 64ce901

File tree

2 files changed

+11
-7
lines changed

2 files changed

+11
-7
lines changed

tests/.env.test.example

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ NODE_ENV=test
77
TZ=UTC
88

99
# Server listen to this port
10-
PORT=3000
10+
PORT=3001
1111

1212
#Cors
1313
CORS_URL=*
@@ -20,7 +20,8 @@ DB_MAX_POOL_SIZE=5
2020

2121
#localhost or IP of the server
2222
# YOUR_TEST_MONGO_DB_HOST_NAME
23-
DB_HOST=mongo
23+
DB_HOST=localhost
24+
# DB_HOST=mongo
2425

2526
DB_PORT=27017
2627

@@ -31,7 +32,8 @@ DB_USER=blogs-test-db-user
3132
DB_USER_PWD=changeit
3233

3334
# Redis
34-
REDIS_HOST=redis
35+
REDIS_HOST=localhost
36+
# REDIS_HOST=redis
3537
REDIS_PORT=6379
3638
REDIS_PASSWORD=changeit
3739

tests/auth/apikey/mock.ts

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,12 +3,14 @@ import ApiKey from '../../../src/database/model/ApiKey';
33
export const API_KEY = 'abc';
44

55
export const mockFindApiKey = jest.fn(async (key: string) => {
6-
if (key == API_KEY) return { key: API_KEY } as ApiKey;
6+
if (key == API_KEY)
7+
return {
8+
key: API_KEY,
9+
permissions: ['GENERAL'],
10+
} as ApiKey;
711
else return null;
812
});
913

1014
jest.mock('../../../src/database/repository/ApiKeyRepo', () => ({
11-
get findByKey() {
12-
return mockFindApiKey;
13-
},
15+
findByKey: mockFindApiKey,
1416
}));

0 commit comments

Comments
 (0)