Skip to content

Commit

Permalink
refactor checklist
Browse files Browse the repository at this point in the history
  • Loading branch information
agissept committed Aug 24, 2023
1 parent 4129e9a commit 2fe5d9d
Show file tree
Hide file tree
Showing 7 changed files with 45 additions and 45 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -23,13 +23,13 @@ describe('course submission acception test', () => {
}

const submissionRequirement = getSubmissionRequirement()
submissionRequirement.API_CAN_INSERT_BOOK.status = true
submissionRequirement.API_CAN_UPDATE_BOOK.status = true
submissionRequirement.API_CAN_DELETE_BOOK.status = true
submissionRequirement.API_CAN_GET_ALL_BOOK.status = true
submissionRequirement.API_CAN_GET_DETAIL_BOOK.status = true
submissionRequirement.PROJECT_HAVE_CORRECT_PORT.status = true
submissionRequirement.PROJECT_HAVE_CORRECT_RUNNER_SCRIPT.status = true
submissionRequirement.api_can_insert_book.status = true
submissionRequirement.api_can_update_book.status = true
submissionRequirement.api_can_delete_book.status = true
submissionRequirement.api_can_get_all_book.status = true
submissionRequirement.api_can_get_detail_book.status = true
submissionRequirement.project_have_correct_port.status = true
submissionRequirement.project_have_correct_runner_script.status = true

const courseSubmissionAcception = new CourseSubmissionAcception(<SubmissionCriteriaCheck>{
reviewChecklistResult: submissionRequirement
Expand Down Expand Up @@ -108,11 +108,11 @@ describe('course submission acception test', () => {
}
}
}

const courseSubmissionAcception = new CourseSubmissionAcception(<SubmissionCriteriaCheck>{}, submissionRatingFactory);
courseSubmissionAcception.accept()

expect(courseSubmissionAcception.rating).toStrictEqual(4)
expect(courseSubmissionAcception.messages).toContain('...')
});
})
})
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@ import getSubmissionRequirements from "../../config/submission-requirement";

describe('mandatory criteria test', () => {
const submissionRequirements = getSubmissionRequirements()
submissionRequirements.PROJECT_HAVE_CORRECT_RUNNER_SCRIPT.status = true
submissionRequirements.PROJECT_HAVE_CORRECT_PORT.status = true
submissionRequirements.project_have_correct_runner_script.status = true
submissionRequirements.project_have_correct_port.status = true
const submissionCriteriaCheckFactory = new SubmissionCriteriaCheckFactory()

it('should grouping failed test by criteria and return approval false', function () {
Expand All @@ -30,12 +30,12 @@ describe('mandatory criteria test', () => {
]

const expectedReviewChecklistResult = getSubmissionRequirements()
expectedReviewChecklistResult.PROJECT_HAVE_CORRECT_PORT.status = true
expectedReviewChecklistResult.PROJECT_HAVE_CORRECT_RUNNER_SCRIPT.status = true
expectedReviewChecklistResult.API_CAN_DELETE_BOOK.status = true
expectedReviewChecklistResult.API_CAN_GET_DETAIL_BOOK.status = true
expectedReviewChecklistResult.API_CAN_UPDATE_BOOK.status = true
expectedReviewChecklistResult.API_CAN_INSERT_BOOK.reason = [
expectedReviewChecklistResult.project_have_correct_port.status = true
expectedReviewChecklistResult.project_have_correct_runner_script.status = true
expectedReviewChecklistResult.api_can_delete_book.status = true
expectedReviewChecklistResult.api_can_get_detail_book.status = true
expectedReviewChecklistResult.api_can_update_book.status = true
expectedReviewChecklistResult.api_can_insert_book.reason = [
{
"name": "[Mandatory] Add Book With Complete Data",
"tests": [
Expand All @@ -49,7 +49,7 @@ describe('mandatory criteria test', () => {
},
]
}]
expectedReviewChecklistResult.API_CAN_GET_ALL_BOOK.reason = [{
expectedReviewChecklistResult.api_can_get_all_book.reason = [{
"name": "[Mandatory] Get All Books",
"tests": [{
"message": "Failed to add book, 404",
Expand All @@ -70,13 +70,13 @@ describe('mandatory criteria test', () => {
expect(submissionCriteriaCheck.approvalStatus).toBeTruthy()

const expectedReviewChecklistResult = getSubmissionRequirements()
expectedReviewChecklistResult.API_CAN_INSERT_BOOK.status = true
expectedReviewChecklistResult.API_CAN_GET_ALL_BOOK.status = true
expectedReviewChecklistResult.API_CAN_GET_DETAIL_BOOK.status = true
expectedReviewChecklistResult.API_CAN_UPDATE_BOOK.status = true
expectedReviewChecklistResult.API_CAN_DELETE_BOOK.status = true
expectedReviewChecklistResult.PROJECT_HAVE_CORRECT_PORT.status = true
expectedReviewChecklistResult.PROJECT_HAVE_CORRECT_RUNNER_SCRIPT.status = true
expectedReviewChecklistResult.api_can_insert_book.status = true
expectedReviewChecklistResult.api_can_get_all_book.status = true
expectedReviewChecklistResult.api_can_get_detail_book.status = true
expectedReviewChecklistResult.api_can_update_book.status = true
expectedReviewChecklistResult.api_can_delete_book.status = true
expectedReviewChecklistResult.project_have_correct_port.status = true
expectedReviewChecklistResult.project_have_correct_runner_script.status = true

expect(submissionCriteriaCheck.reviewChecklistResult).toStrictEqual(expectedReviewChecklistResult)
})
Expand All @@ -85,10 +85,10 @@ describe('mandatory criteria test', () => {
const submissionCriteriaCheck = submissionCriteriaCheckFactory.check(submissionRequirements)
expect(submissionCriteriaCheck.approvalStatus).toBeFalsy()
const expectedReviewChecklistResult = getSubmissionRequirements()
expectedReviewChecklistResult.PROJECT_HAVE_CORRECT_RUNNER_SCRIPT.status = true
expectedReviewChecklistResult.PROJECT_HAVE_CORRECT_PORT.status = true
expectedReviewChecklistResult.project_have_correct_runner_script.status = true
expectedReviewChecklistResult.project_have_correct_port.status = true

expect(submissionCriteriaCheck.reviewChecklistResult).toStrictEqual(expectedReviewChecklistResult)
expect(submissionCriteriaCheck.failurePostmanTest).toBeNull()
});
})
})
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,11 @@ class SubmissionCriteriaCheckFactory {
public check(submissionRequirements: SubmissionRequirement, failurePostmanTest: Array<ResultTestFailure> = null): SubmissionCriteriaCheck{

const postmanRequirements = [
submissionRequirements.API_CAN_INSERT_BOOK,
submissionRequirements.API_CAN_GET_ALL_BOOK,
submissionRequirements.API_CAN_GET_DETAIL_BOOK,
submissionRequirements.API_CAN_UPDATE_BOOK,
submissionRequirements.API_CAN_DELETE_BOOK
submissionRequirements.api_can_insert_book,
submissionRequirements.api_can_get_all_book,
submissionRequirements.api_can_get_detail_book,
submissionRequirements.api_can_update_book,
submissionRequirements.api_can_delete_book
]

postmanRequirements.forEach(postmanRequirement => {
Expand All @@ -29,4 +29,4 @@ class SubmissionCriteriaCheckFactory {
}
}

export default SubmissionCriteriaCheckFactory
export default SubmissionCriteriaCheckFactory
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ export default class SubmissionProjectFactory {

this.checkRunnerCommandUseNodeCommand(runnerCommand)

submissionRequirement.PROJECT_HAVE_CORRECT_RUNNER_SCRIPT.status = true
submissionRequirement.project_have_correct_runner_script.status = true
domainEvent('project has meet requirement')
return {
packageJsonContent: this.packageJsonContent,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,15 +16,15 @@ describe('create submission project test', () => {
it('should throw error when project path not contain package.json', function () {
expect(() => submissionProjectFactory.create(submissionRequirement, null))
.toThrow(new ProjectErrorException('PATH_NOT_CONTAIN_PACKAGE_JSON'))
expect(submissionRequirement.PROJECT_HAVE_CORRECT_RUNNER_SCRIPT.status).toBeFalsy()
expect(submissionRequirement.project_have_correct_runner_script.status).toBeFalsy()
});

it('should throw error when package.json cannot be parsed', function () {
mockFS.readFileSync.mockReturnValue('{ missing curly braces')

expect(() => submissionProjectFactory.create(submissionRequirement, './xxxx'))
.toThrow(new ProjectErrorException('CANNOT_PARSE_PACKAGE_JSON'))
expect(submissionRequirement.PROJECT_HAVE_CORRECT_RUNNER_SCRIPT.status).toBeFalsy()
expect(submissionRequirement.project_have_correct_runner_script.status).toBeFalsy()

});

Expand All @@ -33,7 +33,7 @@ describe('create submission project test', () => {

expect(() => submissionProjectFactory.create(submissionRequirement, './xxxx'))
.toThrow(new ProjectErrorException('PACKAGE_JSON_NOT_CONTAIN_SCRIPT_PROPERTY'))
expect(submissionRequirement.PROJECT_HAVE_CORRECT_RUNNER_SCRIPT.status).toBeFalsy()
expect(submissionRequirement.project_have_correct_runner_script.status).toBeFalsy()

});

Expand All @@ -43,7 +43,7 @@ describe('create submission project test', () => {

expect(() => submissionProjectFactory.create(submissionRequirement,'.'))
.toThrow(new ProjectErrorException('RUNNER_SCRIPT_NOT_FOUND'))
expect(submissionRequirement.PROJECT_HAVE_CORRECT_RUNNER_SCRIPT.status).toBeFalsy()
expect(submissionRequirement.project_have_correct_runner_script.status).toBeFalsy()

});

Expand Down Expand Up @@ -85,7 +85,7 @@ describe('create submission project test', () => {
.create(submissionRequirement, '/home/app/1234')
expect(submissionProject.packageJsonContent).toStrictEqual({ "scripts": { "start": "node src/index.js" }})
expect(submissionProject.packageJsonPath).toStrictEqual('/home/app/1234')
expect(submissionRequirement.PROJECT_HAVE_CORRECT_RUNNER_SCRIPT.status).toBeTruthy()
expect(submissionRequirement.project_have_correct_runner_script.status).toBeTruthy()
});


Expand Down
8 changes: 4 additions & 4 deletions src/service/server/server-service.integration.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ describe('server service test', () => {

// test second sever in same port
await expect(server.run(submissionProject, submissionRequirement)).rejects.toThrow(new Error(`Port ${port} is not available`))
expect(submissionRequirement.PROJECT_HAVE_CORRECT_PORT.status).toBeFalsy()
expect(submissionRequirement.project_have_correct_port.status).toBeFalsy()
await killServer(fakeServerPid, port)
});

Expand All @@ -52,7 +52,7 @@ describe('server service test', () => {
const spy = jest.spyOn(container, 'stop');
await expect(container.run(submissionProject, submissionRequirement)).rejects.toThrow(new ProjectErrorException('PORT_NOT_MEET_REQUIREMENT'))
await expect(spy).toBeCalled()
expect(submissionRequirement.PROJECT_HAVE_CORRECT_PORT.status).toBeFalsy()
expect(submissionRequirement.project_have_correct_port.status).toBeFalsy()
});


Expand All @@ -70,7 +70,7 @@ describe('server service test', () => {

const response = await axios.get(`http://${host}:${port}`)
await expect(response.status).toStrictEqual(200)
expect(submissionRequirement.PROJECT_HAVE_CORRECT_PORT.status).toBeTruthy()
expect(submissionRequirement.project_have_correct_port.status).toBeTruthy()

//kill server
await container.stop()
Expand All @@ -92,7 +92,7 @@ describe('server service test', () => {

const response = await axios.get(`http://${host}:${port}`)
await expect(response.status).toStrictEqual(200)
expect(submissionRequirement.PROJECT_HAVE_CORRECT_PORT.status).toBeTruthy()
expect(submissionRequirement.project_have_correct_port.status).toBeTruthy()


await container.stop()
Expand Down
2 changes: 1 addition & 1 deletion src/service/server/server-service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ class ServerService {

try {
await this.validateServerActive(500, 10000)
submissionRequirement.PROJECT_HAVE_CORRECT_PORT.status = true
submissionRequirement.project_have_correct_port.status = true
raiseDomainEvent('server started')
} catch (e) {
const serverErrorHandler = new ServerErrorHandler(this._errorLog, submissionProject)
Expand Down

0 comments on commit 2fe5d9d

Please sign in to comment.