Skip to content
This repository has been archived by the owner on Sep 12, 2023. It is now read-only.

Commit

Permalink
unit(employee schedule): prepare tests to check uniqueness before create
Browse files Browse the repository at this point in the history
  • Loading branch information
KennethTrecy committed Sep 11, 2022
1 parent 0cbe18b commit ccfc13d
Showing 1 changed file with 45 additions and 8 deletions.
53 changes: 45 additions & 8 deletions routes/api/employee_schedule/create.post.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@ describe("Controller: POST /api/employee_schedule", () => {
requester.customizeRequest({
"body": {
"data": {
"type": "employee_schedule",
"attributes": {
"dayName": employeeeSchedule.dayName,
"scheduleEnd": employeeeSchedule.scheduleEnd,
Expand All @@ -30,11 +29,12 @@ describe("Controller: POST /api/employee_schedule", () => {
"relationships": {
"user": {
"data": {
"type": "user",
"id": String(user.id)
"id": String(user.id),
"type": "user"
}
}
}
},
"type": "employee_schedule"
}
}
})
Expand All @@ -44,6 +44,43 @@ describe("Controller: POST /api/employee_schedule", () => {
requester.expectSuccess()
})

it("cannot accept conflicting info", async() => {
const controller = new Controller()
const { validations } = controller
const bodyValidation = validations[BODY_VALIDATION_INDEX]
const bodyValidationFunction = bodyValidation.intermediate.bind(bodyValidation)
const user = await new UserFactory().beReachableEmployee().insertOne()
const employeeeSchedule = await new EmployeeScheduleFactory()
.user(() => Promise.resolve(user))
.insertOne()
requester.customizeRequest({
"body": {
"data": {
"attributes": {
"dayName": employeeeSchedule.dayName,
"scheduleEnd": employeeeSchedule.scheduleEnd,
"scheduleStart": employeeeSchedule.scheduleStart
},
"relationships": {
"user": {
"data": {
"id": String(user.id),
"type": "user"
}
}
},
"type": "employee_schedule"
}
}
})

await requester.runMiddleware(bodyValidationFunction)

const body = requester.expectFailure(ErrorBag).toJSON()
expect(body).toHaveLength(1)
expect(body).toHaveProperty("0.source.pointer", "data.attributes")
})

it("cannot accept invalid name", async() => {
const controller = new Controller()
const { validations } = controller
Expand All @@ -56,7 +93,6 @@ describe("Controller: POST /api/employee_schedule", () => {
requester.customizeRequest({
"body": {
"data": {
"type": "employee_schedule",
"attributes": {
"dayName": "tue",
"scheduleEnd": employeeeSchedule.scheduleEnd,
Expand All @@ -65,11 +101,12 @@ describe("Controller: POST /api/employee_schedule", () => {
"relationships": {
"user": {
"data": {
"type": "user",
"id": String(user.id)
"id": String(user.id),
"type": "user"
}
}
}
},
"type": "employee_schedule"
}
}
})
Expand Down

0 comments on commit ccfc13d

Please sign in to comment.