Skip to content

Commit

Permalink
Fix broken licence agreement tear-down (#673)
Browse files Browse the repository at this point in the history
https://eaflood.atlassian.net/browse/WATER-4336

In [Improve tear down speed](#671) we made sweeping changes to the tear-down service which is used to support our [water-abstraction-acceptance-tests](https://github.com/DEFRA/water-abstraction-acceptance-tests). The new changes improved the performance of the clean-down.

However, we've spotted that one of the delete statements got lost in the whirlwind of our strategy testing; licence agreements not marked as 'test' but linked to 'test' licences. This a common issue the tear-down service has to deal with due to the way the tests are currently written and the inherited test seed process works.

This change adds the missing statement.
  • Loading branch information
Cruikshanks authored Jan 19, 2024
1 parent cbb71c8 commit 31775a7
Showing 1 changed file with 37 additions and 26 deletions.
63 changes: 37 additions & 26 deletions app/services/data/tear-down/water-schema.service.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@ async function go () {
_financialAgreementTypes(),
_licenceVersionPurposes(),
_licenceVersions(),
_licences(),
_purposesPrimary,
_purposesSecondary(),
_purposesUses(),
Expand All @@ -35,7 +34,15 @@ async function go () {
_sessions()
])

return _regions()
// We have to do region and licence separate from the rest because they are the 'root' test records. The test data
// setup endpoint in water-abstraction-service will create the test region and licence records (plus others). The
// acceptance tests will then generate new data linked to these 'root' records, for example, new bill runs and licence
// agreements.
//
// These do not get flagged as `is_test`. So, to find them for deletion we have to join to the 'root' test records. If
// we included deleting these along with the other statements they could be deleted before statements like, delete
// from bill runs where region is 'test'.
return _regionsAndLicences()
}

async function _billingTransactions () {
Expand Down Expand Up @@ -229,6 +236,14 @@ async function _licenceAgreements () {
WHERE
"is_test" = TRUE;
DELETE
FROM
"water"."licence_agreements" AS "la"
USING "water"."licences" AS "l"
WHERE
"l"."is_test" = TRUE
AND "la"."licence_ref" = "l"."licence_ref";
ALTER TABLE water.licence_agreements ENABLE TRIGGER ALL;
`)
}
Expand Down Expand Up @@ -325,30 +340,6 @@ async function _licenceVersions () {
`)
}

async function _licences () {
return db.raw(`
ALTER TABLE water.licences DISABLE TRIGGER ALL;
DELETE
FROM
"water"."licences"
WHERE
"is_test" = TRUE;
ALTER TABLE water.licences ENABLE TRIGGER ALL;
`)
}

async function _regions () {
return db.raw(`
DELETE
FROM
"water"."regions"
WHERE
"is_test" = TRUE;
`)
}

async function _purposesPrimary () {
return db.raw(`
DELETE
Expand Down Expand Up @@ -421,6 +412,26 @@ async function _sessions () {
`)
}

async function _regionsAndLicences () {
return db.raw(`
ALTER TABLE water.licences DISABLE TRIGGER ALL;
DELETE
FROM
"water"."licences"
WHERE
"is_test" = TRUE;
DELETE
FROM
"water"."regions"
WHERE
"is_test" = TRUE;
ALTER TABLE water.licences ENABLE TRIGGER ALL;
`)
}

module.exports = {
go
}

0 comments on commit 31775a7

Please sign in to comment.