Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix return version tests #1295

Merged
merged 4 commits into from
Aug 30, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 8 additions & 8 deletions test/models/return-version.model.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ const { describe, it, beforeEach } = exports.lab = Lab.script()
const { expect } = Code

// Test helpers
const { randomInteger } = require('../support/general.js')
const { randomInteger, randomRegionCode } = require('../support/general.js')
const LicenceHelper = require('../support/helpers/licence.helper.js')
const LicenceModel = require('../../app/models/licence.model.js')
const ModLogHelper = require('../support/helpers/mod-log.helper.js')
Expand Down Expand Up @@ -198,7 +198,7 @@ describe('Return Version model', () => {

describe('when a return version has mod log history', () => {
beforeEach(async () => {
const regionCode = randomInteger(1, 9)
const regionCode = randomRegionCode()
const firstNaldId = randomInteger(100, 99998)

await ModLogHelper.add({
Expand Down Expand Up @@ -279,7 +279,7 @@ describe('Return Version model', () => {

describe('and has mod log history', () => {
beforeEach(async () => {
const regionCode = randomInteger(1, 9)
const regionCode = randomRegionCode()
const firstNaldId = randomInteger(100, 99998)

await ModLogHelper.add({ externalId: `${regionCode}:${firstNaldId}`, returnVersionId, userId: 'FIRST' })
Expand Down Expand Up @@ -343,7 +343,7 @@ describe('Return Version model', () => {

describe('and none of the mod log history has notes', () => {
beforeEach(async () => {
const regionCode = randomInteger(1, 9)
const regionCode = randomRegionCode()
const firstNaldId = randomInteger(100, 99998)

await ModLogHelper.add({
Expand All @@ -366,7 +366,7 @@ describe('Return Version model', () => {

describe('and some of the mod log history has notes', () => {
beforeEach(async () => {
const regionCode = randomInteger(1, 9)
const regionCode = randomRegionCode()
const firstNaldId = randomInteger(100, 99998)

await ModLogHelper.add({
Expand Down Expand Up @@ -394,7 +394,7 @@ describe('Return Version model', () => {

returnVersionId = id

const regionCode = randomInteger(1, 9)
const regionCode = randomRegionCode()
const firstNaldId = randomInteger(100, 99998)

await ModLogHelper.add({
Expand Down Expand Up @@ -462,7 +462,7 @@ describe('Return Version model', () => {

describe('but the mod log history has no reason description recorded in the first entry', () => {
beforeEach(async () => {
const regionCode = randomInteger(1, 9)
const regionCode = randomRegionCode()
const firstNaldId = randomInteger(100, 99998)

await ModLogHelper.add({
Expand All @@ -484,7 +484,7 @@ describe('Return Version model', () => {

describe('and the mod log history has a reason description recorded in the first entry', () => {
beforeEach(async () => {
const regionCode = randomInteger(1, 9)
const regionCode = randomRegionCode()
const firstNaldId = randomInteger(100, 99998)

await ModLogHelper.add({
Expand Down
16 changes: 16 additions & 0 deletions test/support/general.js
Original file line number Diff line number Diff line change
Expand Up @@ -95,8 +95,24 @@ function selectRandomEntry (data) {
return data[randomIndex]
}

/**
* Generates a random region code
*
* Region codes should be between 1 and 9 based on the fixed region reference data.
*
* We see issues with this small range when tables have unique constraints when building external id's.
*
* This function is here to encapsulate this issue and remove any need to explain the issue else where in the tests.
*
* @returns a random number
*/
function randomRegionCode () {
return randomInteger(1, 999999)
}

module.exports = {
postRequestOptions,
randomInteger,
randomRegionCode,
selectRandomEntry
}
4 changes: 2 additions & 2 deletions test/support/helpers/mod-log.helper.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
*/

const ModLogModel = require('../../../app/models/mod-log.model.js')
const { randomInteger } = require('../general.js')
const { randomInteger, randomRegionCode } = require('../general.js')
const { generateLicenceRef } = require('./licence.helper.js')

/**
Expand Down Expand Up @@ -44,7 +44,7 @@ function add (data = {}) {
* @returns {object} - Returns the set defaults with the override data spread
*/
function defaults (data = {}) {
const regionCode = randomInteger(1, 9)
const regionCode = randomRegionCode()

const defaults = {
externalId: generateRegionNaldPatternExternalId(regionCode),
Expand Down
4 changes: 2 additions & 2 deletions test/support/helpers/return-version.helper.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
*/

const { generateUUID } = require('../../../app/lib/general.lib.js')
const { randomInteger } = require('../general.js')
const { randomInteger, randomRegionCode } = require('../general.js')
const ReturnVersionModel = require('../../../app/models/return-version.model.js')

/**
Expand Down Expand Up @@ -46,7 +46,7 @@ function defaults (data = {}) {
const version = data.version ? data.version : 100

const defaults = {
externalId: `9:${randomInteger(100, 99999)}:${version}`,
externalId: `${randomRegionCode()}:${randomInteger(100, 99999)}:${version}`,
licenceId: generateUUID(),
reason: 'new-licence',
startDate: new Date('2022-04-01'),
Expand Down
Loading