-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Hendry Tanaka
committed
Jul 27, 2024
1 parent
a9fccc6
commit 8ec0d78
Showing
6 changed files
with
402 additions
and
94 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
194 changes: 194 additions & 0 deletions
194
server/apps/core/src/modules/master/test/dto/master.department.dto.unit-spec.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,194 @@ | ||
import { | ||
MasterDepartmentAddDTO, | ||
MasterDepartmentEditDTO, | ||
} from '@core/master/dto/master.department' | ||
import { faker } from '@faker-js/faker' | ||
import { testCaption } from '@utility/string' | ||
import { plainToInstance } from 'class-transformer' | ||
import { validate } from 'class-validator' | ||
|
||
const falseCasePayload = { | ||
add: [ | ||
{ | ||
expectedToContain: 'code must be longer than or equal to 8 characters', | ||
targetClass: MasterDepartmentAddDTO, | ||
testType: -1, | ||
data: { | ||
code: faker.string.alpha({ length: 5, casing: 'upper' }), | ||
name: faker.company.name(), | ||
configuration: { | ||
default_consultation_treatment: {}, | ||
treatment: [], | ||
doctor: [], | ||
}, | ||
}, | ||
}, | ||
{ | ||
expectedToContain: 'code must be shorter than or equal to 24 characters', | ||
targetClass: MasterDepartmentAddDTO, | ||
testType: -1, | ||
data: { | ||
code: faker.string.alpha({ length: 25, casing: 'upper' }), | ||
name: faker.company.name(), | ||
configuration: { | ||
default_consultation_treatment: {}, | ||
treatment: [], | ||
doctor: [], | ||
}, | ||
}, | ||
}, | ||
{ | ||
expectedToContain: 'name should not be empty', | ||
targetClass: MasterDepartmentAddDTO, | ||
testType: -1, | ||
data: { | ||
code: faker.string.alpha({ length: 24, casing: 'upper' }), | ||
configuration: { | ||
default_consultation_treatment: {}, | ||
treatment: [], | ||
doctor: [], | ||
}, | ||
}, | ||
}, | ||
{ | ||
expectedToContain: 'Correct data', | ||
targetClass: MasterDepartmentAddDTO, | ||
testType: 1, | ||
data: { | ||
code: faker.string.alpha({ length: 24, casing: 'upper' }), | ||
name: faker.company.name(), | ||
configuration: { | ||
default_consultation_treatment: {}, | ||
treatment: [], | ||
doctor: [], | ||
}, | ||
}, | ||
}, | ||
], | ||
edit: [ | ||
{ | ||
expectedToContain: 'code must be longer than or equal to 8 characters', | ||
targetClass: MasterDepartmentEditDTO, | ||
testType: -1, | ||
data: { | ||
code: faker.string.alpha({ length: 5, casing: 'upper' }), | ||
name: faker.company.name(), | ||
configuration: { | ||
default_consultation_treatment: {}, | ||
treatment: [], | ||
doctor: [], | ||
}, | ||
__v: 0, | ||
}, | ||
}, | ||
{ | ||
expectedToContain: 'code must be shorter than or equal to 24 characters', | ||
targetClass: MasterDepartmentEditDTO, | ||
testType: -1, | ||
data: { | ||
code: faker.string.alpha({ length: 25, casing: 'upper' }), | ||
name: faker.company.name(), | ||
configuration: { | ||
default_consultation_treatment: {}, | ||
treatment: [], | ||
doctor: [], | ||
}, | ||
__v: 0, | ||
}, | ||
}, | ||
{ | ||
expectedToContain: 'name should not be empty', | ||
targetClass: MasterDepartmentEditDTO, | ||
testType: -1, | ||
data: { | ||
code: faker.string.alpha({ length: 24, casing: 'upper' }), | ||
configuration: { | ||
default_consultation_treatment: {}, | ||
treatment: [], | ||
doctor: [], | ||
}, | ||
__v: 0, | ||
}, | ||
}, | ||
{ | ||
expectedToContain: '__v should not be empty', | ||
targetClass: MasterDepartmentEditDTO, | ||
testType: -1, | ||
data: { | ||
code: faker.string.alpha({ length: 24, casing: 'upper' }), | ||
name: faker.company.name(), | ||
configuration: { | ||
default_consultation_treatment: {}, | ||
treatment: [], | ||
doctor: [], | ||
}, | ||
}, | ||
}, | ||
{ | ||
expectedToContain: 'Correct data', | ||
targetClass: MasterDepartmentEditDTO, | ||
testType: 1, | ||
data: { | ||
code: faker.string.alpha({ length: 24, casing: 'upper' }), | ||
name: faker.company.name(), | ||
configuration: { | ||
default_consultation_treatment: {}, | ||
treatment: [], | ||
doctor: [], | ||
}, | ||
__v: 0, | ||
}, | ||
}, | ||
], | ||
} | ||
describe('Master Department DTO Test', () => { | ||
describe(testCaption('ADD', 'data', 'Master department add'), () => { | ||
for (const tKey of falseCasePayload.add) { | ||
it( | ||
testCaption( | ||
tKey.testType < 0 ? 'NEGATIVE' : 'POSITIVE', | ||
'data', | ||
`${tKey.expectedToContain}`, | ||
{ | ||
tab: 1, | ||
} | ||
), | ||
async () => { | ||
const ofImportDto = plainToInstance(tKey.targetClass, tKey.data) | ||
const errors = await validate(ofImportDto) | ||
if (tKey.testType < 0) { | ||
expect(errors.length).not.toBe(0) | ||
expect(JSON.stringify(errors)).toContain(tKey.expectedToContain) | ||
} else { | ||
expect(errors.length).toBe(0) | ||
} | ||
} | ||
) | ||
} | ||
}) | ||
|
||
describe(testCaption('EDIT', 'data', 'Master department edit'), () => { | ||
for (const tKey of falseCasePayload.edit) { | ||
it( | ||
testCaption( | ||
tKey.testType < 0 ? 'NEGATIVE' : 'POSITIVE', | ||
'data', | ||
`${tKey.expectedToContain}`, | ||
{ | ||
tab: 1, | ||
} | ||
), | ||
async () => { | ||
const ofImportDto = plainToInstance(tKey.targetClass, tKey.data) | ||
const errors = await validate(ofImportDto) | ||
if (tKey.testType < 0) { | ||
expect(errors.length).not.toBe(0) | ||
expect(JSON.stringify(errors)).toContain(tKey.expectedToContain) | ||
} else { | ||
expect(errors.length).toBe(0) | ||
} | ||
} | ||
) | ||
} | ||
}) | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.