Skip to content

Commit

Permalink
DRY out insert court cases helper functions (ministryofjustice#157)
Browse files Browse the repository at this point in the history
* Add generic insertCourtCasesWithFields method to setup test data

* Remove redundant insertDummyCourtCaseWithLock function

* Remove redundant insertMultipleDummyCourtCasesWithLock function

* Fix failing lock test

We need to seed error count and trigger count when testing locks, if case don't have error/trigger locking will fail

* Rename visibleForces in resolve trigger test

* Remove redundant insertCourtCasesWithCourtDates

* Remove redundant insertCourtCasesWithOrgCodes

* Remove redundant insertCourtCasesWithCourtNames

* Fix insertCourtCasesWithFields seeds court dates

* Remove redundant insertMultipleDummyCourtCasesWithResolutionTimestamp

* Remove redundant insertCourtCasesWithUrgencies function

* Simplify list court cases test setup

* Simplify add notes integration test

* Delete unused task from cypress config

* Dry out insertMultipleDummyCourtCases function

* DRY out the remaining insert court cases helper functions

* Seed multiple cases with uniq defendant name
  • Loading branch information
C-gyorfi authored Jan 25, 2023
1 parent d8cb4ef commit 7bf09f8
Show file tree
Hide file tree
Showing 10 changed files with 384 additions and 491 deletions.
64 changes: 4 additions & 60 deletions cypress.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,17 +5,9 @@ import User from "./src/services/entities/User"
import deleteFromTable from "./test/utils/deleteFromTable"
import { getCourtCaseById } from "./test/utils/getCourtCaseById"
import {
insertCourtCases,
insertCourtCasesWithCourtDates,
insertCourtCasesWithCourtNames,
insertCourtCasesWithFieldOverrides,
insertCourtCasesWithOrgCodes,
insertCourtCasesWithFields,
insertDummyCourtCasesWithNotes,
insertDummyCourtCasesWithUrgencies,
insertDummyCourtCaseWithLock,
insertMultipleDummyCourtCases,
insertMultipleDummyCourtCasesWithLock,
insertMultipleDummyCourtCasesWithResolutionTimestamp
insertMultipleDummyCourtCases
} from "./test/utils/insertCourtCases"
import insertException from "./test/utils/manageExceptions"
import { insertTriggers } from "./test/utils/manageTriggers"
Expand Down Expand Up @@ -54,67 +46,19 @@ export default defineConfig({

return null
},
insertCourtCasesWithOrgCodes(orgCodes: string[]) {
return insertCourtCasesWithOrgCodes(orgCodes)
},

insertMultipleDummyCourtCases(params: { numToInsert: number; force: string }) {
return insertMultipleDummyCourtCases(params.numToInsert, params.force)
},

insertCourtCasesWithCourtDates(params: { courtDate: Date[]; force: string }) {
return insertCourtCasesWithCourtDates(params.courtDate, params.force)
},

insertCourtCasesWithCourtNames(params: { courtNames: string[]; force: string }) {
return insertCourtCasesWithCourtNames(params.courtNames, params.force)
},

insertCourtCasesWithFieldOverrides(params: {
keywords: { defendantNames?: string[]; courtNames?: string[] }
force: string
}) {
return insertCourtCasesWithFieldOverrides(params.keywords, params.force)
},

insertDummyCourtCaseWithLock(params: {
errorLockedByUsername: string
triggerLockedByUsername: string
orgCodes: string[]
}) {
return insertDummyCourtCaseWithLock(
params.errorLockedByUsername,
params.triggerLockedByUsername,
params.orgCodes
)
},

insertMultipleDummyCourtCasesWithResolutionTimestamp(params: {
resolutionTimestamps: (Date | null)[]
orgCode: string
}) {
return insertMultipleDummyCourtCasesWithResolutionTimestamp(params.resolutionTimestamps, params.orgCode)
},

insertMultipleDummyCourtCasesWithLock(params: {
lockHolders: { errorLockedByUsername?: string; triggerLockedByUsername?: string }[]
orgCode: string
}) {
return insertMultipleDummyCourtCasesWithLock(params.lockHolders, params.orgCode)
},

insertCourtCasesWithUrgencies(params: { urgencies: boolean[]; force: string }) {
return insertDummyCourtCasesWithUrgencies(params.urgencies, params.force)
insertCourtCasesWithFields(cases: Partial<CourtCase>[]) {
return insertCourtCasesWithFields(cases)
},

insertCourtCasesWithNotes(params: { caseNotes: { user: string; text: string }[][]; force: string }) {
return insertDummyCourtCasesWithNotes(params.caseNotes, params.force)
},

insertCourtCases(params: { courtCases: CourtCase[] }) {
return insertCourtCases(params.courtCases)
},

clearCourtCases() {
return deleteFromTable(CourtCase)
},
Expand Down
80 changes: 46 additions & 34 deletions cypress/e2e/court-cases/caseDetails.cy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ describe("Case details", () => {
})

it("should be accessible", () => {
cy.task("insertCourtCasesWithOrgCodes", ["01"])
cy.task("insertCourtCasesWithFields", [{ orgForPoliceFilter: "01" }])
const triggers: TestTrigger[] = [
{
triggerId: 0,
Expand All @@ -54,7 +54,7 @@ describe("Case details", () => {
})

it("should load case details for the case that this user can see", () => {
cy.task("insertCourtCasesWithOrgCodes", ["01"])
cy.task("insertCourtCasesWithFields", [{ orgForPoliceFilter: "01" }])
const triggers: TestTrigger[] = [
{
triggerId: 0,
Expand Down Expand Up @@ -124,7 +124,7 @@ describe("Case details", () => {
})

it("should return 404 for a case that this user can not see", () => {
cy.task("insertCourtCasesWithOrgCodes", ["02"])
cy.task("insertCourtCasesWithFields", [{ orgForPoliceFilter: "02" }])
cy.login("[email protected]", "password")

cy.request({
Expand Down Expand Up @@ -155,13 +155,15 @@ describe("Case details", () => {
})

it("should lock a case when a user views a case details page", () => {
cy.task("insertDummyCourtCaseWithLock", {
errorLockedByUsername: null,
triggerLockedByUsername: null,
orgCodes: ["02"],
errorCount: 1,
triggerCount: 1
})
cy.task("insertCourtCasesWithFields", [
{
errorLockedByUsername: null,
triggerLockedByUsername: null,
orgForPoliceFilter: "02",
errorCount: 1,
triggerCount: 1
}
])

cy.login("[email protected]", "password")
cy.visit("/bichard/court-cases/0")
Expand All @@ -174,13 +176,15 @@ describe("Case details", () => {

it("should not lock a court case when its already locked", () => {
const existingUserLock = "Another name"
cy.task("insertDummyCourtCaseWithLock", {
errorLockedByUsername: existingUserLock,
triggerLockedByUsername: existingUserLock,
orgCodes: ["01"],
errorCount: 1,
triggerCount: 1
})
cy.task("insertCourtCasesWithFields", [
{
errorLockedByUsername: existingUserLock,
triggerLockedByUsername: existingUserLock,
orgForPoliceFilter: "01",
errorCount: 1,
triggerCount: 1
}
])

cy.login("[email protected]", "password")
cy.visit("/bichard/court-cases/0")
Expand All @@ -191,11 +195,15 @@ describe("Case details", () => {

it("should unlock and lock a court case when its already locked", () => {
const existingUserLock = "Another name"
cy.task("insertDummyCourtCaseWithLock", {
errorLockedByUsername: existingUserLock,
triggerLockedByUsername: existingUserLock,
orgCodes: ["02"]
})
cy.task("insertCourtCasesWithFields", [
{
errorLockedByUsername: existingUserLock,
triggerLockedByUsername: existingUserLock,
orgForPoliceFilter: "02",
errorCount: 1,
triggerCount: 1
}
])

cy.login("[email protected]", "password")
cy.visit("/bichard/court-cases/0")
Expand All @@ -216,11 +224,14 @@ describe("Case details", () => {

it("should resolve a trigger after clicking the button", () => {
const userWithGeneralHandlerPermission = "Bichard02"
cy.task("insertDummyCourtCaseWithLock", {
errorLockedByUsername: userWithGeneralHandlerPermission,
triggerLockedByUsername: userWithGeneralHandlerPermission,
orgCodes: ["02"]
})
cy.task("insertCourtCasesWithFields", [
{
errorLockedByUsername: userWithGeneralHandlerPermission,
triggerLockedByUsername: userWithGeneralHandlerPermission,
orgForPoliceFilter: "02"
}
])

const triggers: TestTrigger[] = [
{
triggerId: 0,
Expand Down Expand Up @@ -249,11 +260,13 @@ describe("Case details", () => {
})

it("should resubmit a case when the resubmit button is clicked", () => {
cy.task("insertDummyCourtCaseWithLock", {
errorLockedByUsername: null,
triggerLockedByUsername: null,
orgCodes: ["02"]
})
cy.task("insertCourtCasesWithFields", [
{
errorLockedByUsername: null,
triggerLockedByUsername: null,
orgForPoliceFilter: "02"
}
])

cy.login("[email protected]", "password")

Expand All @@ -277,8 +290,7 @@ describe("Case details", () => {
})

it("should resubmit a case when updates are made and the resubmit button is clicked", () => {
cy.task("insertCourtCasesWithOrgCodes", ["02"])

cy.task("insertCourtCasesWithFields", [{ orgForPoliceFilter: "02" }])
cy.login("[email protected]", "password")

cy.visit("/bichard/court-cases/0")
Expand Down
12 changes: 6 additions & 6 deletions cypress/e2e/court-cases/notes/add.cy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ describe("Case details", () => {
})

it("should be accessible", () => {
cy.task("insertCourtCasesWithOrgCodes", ["01"])
cy.task("insertCourtCasesWithFields", [{ orgForPoliceFilter: "01" }])
const triggers: TestTrigger[] = [
{
triggerId: 0,
Expand All @@ -50,7 +50,7 @@ describe("Case details", () => {
})

it("should be able to add a note when case is visible to the user and not locked by another user", () => {
cy.task("insertCourtCasesWithOrgCodes", ["01"])
cy.task("insertCourtCasesWithFields", [{ orgForPoliceFilter: "01" }])
const triggers: TestTrigger[] = [
{
triggerId: 0,
Expand Down Expand Up @@ -78,7 +78,7 @@ describe("Case details", () => {
})

it("should be able to add a long note", () => {
cy.task("insertCourtCasesWithOrgCodes", ["01"])
cy.task("insertCourtCasesWithFields", [{ orgForPoliceFilter: "01" }])
const triggers: TestTrigger[] = [
{
triggerId: 0,
Expand Down Expand Up @@ -109,7 +109,7 @@ describe("Case details", () => {
})

it("should show error message when note text is empty", () => {
cy.task("insertCourtCasesWithOrgCodes", ["01"])
cy.task("insertCourtCasesWithFields", [{ orgForPoliceFilter: "01" }])
const triggers: TestTrigger[] = [
{
triggerId: 0,
Expand All @@ -134,7 +134,7 @@ describe("Case details", () => {
})

it("Adding an empty note doesn't add a note, when the case is visible to the user and not locked by another user", () => {
cy.task("insertCourtCasesWithOrgCodes", ["01"])
cy.task("insertCourtCasesWithFields", [{ orgForPoliceFilter: "01" }])
const triggers: TestTrigger[] = [
{
triggerId: 0,
Expand All @@ -158,7 +158,7 @@ describe("Case details", () => {
})

it("should return 404 for a case that this user can not see", () => {
cy.task("insertCourtCasesWithOrgCodes", ["02"])
cy.task("insertCourtCasesWithFields", [{ orgForPoliceFilter: "02" }])
cy.login("[email protected]", "password")

cy.request({
Expand Down
Loading

0 comments on commit 7bf09f8

Please sign in to comment.