Skip to content

Commit 77d11b7

Browse files
authored
Merge pull request #39 from dohun31/feat/#38-B
Feat/#38-B: μ›Œν¬μŠ€νŽ˜μ΄μŠ€ κ°€μ Έμ˜€λŠ” API ν…ŒμŠ€νŠΈ
2 parents d2723c8 + 94880ce commit 77d11b7

File tree

4 files changed

+57
-10
lines changed

4 files changed

+57
-10
lines changed
Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
const { getWorkspaces } = require('./service');
2+
const userModel = require('@apis/user/model');
3+
const workspaceModel = require('@apis/workspace/model');
4+
const { default: AuthorizationError } = require('@errors/authorization-error');
5+
6+
jest.mock('@apis/user/model', () => {
7+
return { findOne: jest.fn() };
8+
});
9+
10+
jest.mock('@apis/workspace/model', () => {
11+
return { find: jest.fn() };
12+
});
13+
14+
describe('getWorkspaces()', () => {
15+
const successfulUser = '';
16+
const successfulWorkspaces: Object[] = [];
17+
18+
it('정상적인 μœ μ € 아이디λ₯Ό λ°›μ•„μ„œ μ„±κ³΅μ μœΌλ‘œ μ›Œν¬μŠ€νŽ˜μ΄μŠ€λ₯Ό κ°€μ Έμ˜¨λ‹€.', async () => {
19+
// arrange
20+
userModel.findOne.mockResolvedValueOnce(successfulUser);
21+
workspaceModel.find.mockResolvedValueOnce(successfulWorkspaces);
22+
23+
// act
24+
const workspaces = await getWorkspaces('id', 'id');
25+
26+
// assert
27+
expect(workspaces).toEqual(successfulWorkspaces);
28+
});
29+
30+
it('비정상적인 μœ μ € 아이디λ₯Ό λ°›μœΌλ©΄ μ—λŸ¬λ₯Ό λ˜μ§„λ‹€.', async () => {
31+
// arrange
32+
const user1 = 1;
33+
const user2 = 2;
34+
35+
// act & assert
36+
expect(() => getWorkspaces(user1, user2)).rejects.toThrow(
37+
AuthorizationError,
38+
);
39+
});
40+
});
41+
42+
export {};
Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,10 @@
11
import CustomError from '.';
22
import { UNAUTHORIZED } from '@constants/http-status';
33

4-
export default class AuthorizationError extends CustomError {
4+
class AuthorizationError extends CustomError {
55
constructor(message = 'Unauthorized') {
66
super(message, UNAUTHORIZED);
77
}
88
}
9+
10+
export default AuthorizationError;

β€Žserver/errors/index.tsβ€Ž

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import { INTERNAL_SERVER_ERROR } from '@constants/http-status';
22

3-
export default class CustomError extends Error {
3+
class CustomError extends Error {
44
message!: string;
55
status!: number;
66

@@ -14,3 +14,5 @@ export default class CustomError extends Error {
1414
this.status = status;
1515
}
1616
}
17+
18+
export default CustomError;

β€Žserver/jest.config.jsβ€Ž

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,12 @@ module.exports = {
22
preset: 'ts-jest', // to use typescript
33
verbose: true,
44
moduleNameMapper: {
5-
"@apis/(.*)": "<rootDir>/apis/$1",
6-
"@config": "<rootDir>/config",
7-
"@constants/(.*)": "<rootDir>/constants/$1",
8-
"@db": "<rootDir>/db",
9-
"@middlewares/(.*)": "<rootDir>/middlewares/$1",
10-
"@utils/(.*)": "<rootDir>/utils/$1"
11-
}
12-
}
5+
'@apis/(.*)': '<rootDir>/apis/$1',
6+
'@config': '<rootDir>/config',
7+
'@constants/(.*)': '<rootDir>/constants/$1',
8+
'@db': '<rootDir>/db',
9+
'@middlewares/(.*)': '<rootDir>/middlewares/$1',
10+
'@utils/(.*)': '<rootDir>/utils/$1',
11+
'@errors/(.*)': '<rootDir>/errors/$1',
12+
},
13+
};

0 commit comments

Comments
Β (0)