-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Loading status checks…
Amend no returns message in view licence Returns tab (#1087)
* View Licence Returns no return messages When a licence has returns show the returns table. When the licence does not have returns and or requirements then the messages show need to show different messages.
1 parent
177d0fe
commit 3f05d48
Showing
9 changed files
with
273 additions
and
162 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
35 changes: 35 additions & 0 deletions
35
app/services/licences/determine-licence-has-return-versions.service.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
'use strict' | ||
|
||
/** | ||
* Determines if a licence has requirements | ||
* @module DetermineLicenceHasReturnVersionsService | ||
*/ | ||
|
||
const ReturnVersionModel = require('../../models/return-version.model.js') | ||
|
||
/** | ||
* Determines if a licence has requirements | ||
* | ||
* @param {string} licenceId - The UUID of the licence to determine if return versions exist | ||
* | ||
* @returns {Promise<Boolean>} true if the licence has return versions else false | ||
*/ | ||
async function go (licenceId) { | ||
const requirement = await _fetch(licenceId) | ||
|
||
return !!requirement | ||
} | ||
|
||
async function _fetch (licenceId) { | ||
return ReturnVersionModel.query() | ||
.select([ | ||
'id' | ||
]) | ||
.where('licenceId', licenceId) | ||
.limit(1) | ||
.first() | ||
} | ||
|
||
module.exports = { | ||
go | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
44 changes: 44 additions & 0 deletions
44
test/services/licences/determine-licence-has-return-versions.service.test.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
'use strict' | ||
|
||
// Test framework dependencies | ||
const Lab = require('@hapi/lab') | ||
const Code = require('@hapi/code') | ||
|
||
const { describe, it, beforeEach } = exports.lab = Lab.script() | ||
const { expect } = Code | ||
|
||
// Test helpers | ||
const DatabaseSupport = require('../../support/database.js') | ||
const ReturnVersionHelper = require('../../support/helpers/return-version.helper.js') | ||
|
||
// Thing under test | ||
const FetchLicenceHasRequirementsService = | ||
require('../../../app/services/licences/determine-licence-has-return-versions.service.js') | ||
|
||
describe('Fetch Licence Has Requirements service', () => { | ||
const licenceId = 'e004c0c9-0316-42fc-a6e3-5ae9a271b3c6' | ||
|
||
beforeEach(async () => { | ||
await DatabaseSupport.clean() | ||
}) | ||
|
||
describe('when the licence has return versions', () => { | ||
beforeEach(async () => { | ||
await ReturnVersionHelper.add({ licenceId }) | ||
}) | ||
|
||
it('returns true', async () => { | ||
const result = await FetchLicenceHasRequirementsService.go(licenceId) | ||
|
||
expect(result).to.be.true() | ||
}) | ||
}) | ||
|
||
describe('when the licence does not have return versions', () => { | ||
it('returns false', async () => { | ||
const result = await FetchLicenceHasRequirementsService.go('ed3b9b1a-94e0-480c-8ad6-60e05f5fa9f4') | ||
|
||
expect(result).to.be.false() | ||
}) | ||
}) | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters