Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Test case 추가 #2

Merged
merged 20 commits into from
Nov 6, 2022
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
[Account/Test] checkPermission
  • Loading branch information
rojiwon0325 committed Nov 6, 2022
commit fb2ff79711ca63988f825f8f8713750635eba75e
2 changes: 1 addition & 1 deletion .github/workflows/push_cov_report.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ jobs:

strategy:
matrix:
node-version: [16.x]
node-version: [18.x]

steps:
- name: Checkout 🛎️
Expand Down
65 changes: 43 additions & 22 deletions src/api/account/test/account.domain.spec.ts
Original file line number Diff line number Diff line change
@@ -1,13 +1,10 @@
/* eslint-disable @typescript-eslint/no-unused-vars */
import { Account } from '@ACCOUNT/domain';
type Required = keyof Pick<Account.Property, 'username' | 'email' | 'password'>;
type Props = Pick<Account.Property, Required> &
Partial<Omit<Account.Property, Required>>;
const { get, getPublic, checkPermission, setUsername } = Account;
const now = new Date();

describe('Account Domain Unit Test', () => {
const { get, getPublic, checkPermission, setUsername } = Account;
const now = new Date();
const getExample: Props[] = [
it.each<Get>([
{
email: 'test@test.com',
username: 'testuser',
Expand All @@ -28,8 +25,7 @@ describe('Account Domain Unit Test', () => {
created_at: now,
updated_at: now,
},
];
it.each(getExample)('Account.get', (data) => {
])('Account.get', (data) => {
const { created_at, updated_at, ...account } = get(data);
if (data.created_at != null) {
expect(created_at).toEqual(data.created_at);
Expand All @@ -47,32 +43,57 @@ describe('Account Domain Unit Test', () => {
});
});

const agg = get({
id: 1,
email: 'test@test.com',
username: 'testuser',
password: '1234',
role: 'Manager',
});

it('Account.getPublic', () => {
const result = getPublic(agg);
const data = get({
id: 1,
email: 'test@test.com',
username: 'testuser',
password: '1234',
role: 'Manager',
});
const result = getPublic(data);
expect(result).toEqual({
id: agg.id,
email: agg.email,
username: agg.username,
role: agg.role,
id: data.id,
email: data.email,
username: data.username,
role: data.role,
});
return;
});

it('checkPermission', () => {
it.each<CheckPermission>([
{ user: 'Admin', permission: 'Admin' },
{ user: 'Admin', permission: 'Normal' },
{ user: 'Admin', permission: 'Manager' },
{ user: 'Manager', permission: 'Manager' },
{ user: 'Manager', permission: 'Normal' },
{ user: 'Normal', permission: 'Normal' },
])('Account.checkPermission - true', (data) => {
const result = checkPermission(data);
expect(result).toBe(true);
return;
});
it.each<CheckPermission>([
{ user: 'Normal', permission: 'Admin' },
{ user: 'Normal', permission: 'Manager' },
{ user: 'Manager', permission: 'Admin' },
])('Account.checkPermission - false', (data) => {
const result = checkPermission(data);
expect(result).toBe(false);
});

it('setUsername', () => {
return;
});
it('setPassword', () => {
return;
});
});

type Required = keyof Pick<Account.Property, 'username' | 'email' | 'password'>;
type Get = Pick<Account.Property, Required> &
Partial<Omit<Account.Property, Required>>;
type CheckPermission = {
readonly user: Account.Permission;
readonly permission: Account.Permission;
};