-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
create tests for the mergeSectorAndSubSectorFunction, amend function …
…so that it does not include the sector_depends key value pair when there is no value
- Loading branch information
Richard Pentecost
committed
Mar 1, 2024
1 parent
e1b4bfc
commit bed113d
Showing
2 changed files
with
73 additions
and
4 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
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,70 @@ | ||
const { mergeSectorAndSubSectorParams } = require('../../services') | ||
|
||
describe('mergeSectorAndSubSectorParams', () => { | ||
const basicRequestBody = { | ||
sortby: 'desc', | ||
archived: 'false', | ||
area: [], | ||
uk_postcode: undefined, | ||
} | ||
it('should merge the sector and sub sector params when both are present', () => { | ||
const reqBody = { | ||
...basicRequestBody, | ||
sector_descends: ['sector_uuid1'], | ||
sub_sector_descends: ['sub_sector_uuid1'], | ||
} | ||
|
||
expect(mergeSectorAndSubSectorParams(reqBody)).to.deep.equal({ | ||
...basicRequestBody, | ||
sector_descends: ['sector_uuid1', 'sub_sector_uuid1'], | ||
}) | ||
}) | ||
|
||
it('should merge all sector and sub sector params when multiple of both are present', () => { | ||
const reqBody = { | ||
...basicRequestBody, | ||
sector_descends: ['sector_uuid1', 'sector_uuid2'], | ||
sub_sector_descends: ['sub_sector_uuid1', 'sub_sector_uuid2'], | ||
} | ||
|
||
expect(mergeSectorAndSubSectorParams(reqBody)).to.deep.equal({ | ||
...basicRequestBody, | ||
sector_descends: [ | ||
'sector_uuid1', | ||
'sector_uuid2', | ||
'sub_sector_uuid1', | ||
'sub_sector_uuid2', | ||
], | ||
}) | ||
}) | ||
|
||
it('should include just the sector params if there are not any sub sector params', () => { | ||
const reqBody = { | ||
...basicRequestBody, | ||
sector_descends: ['sector_uuid1', 'sector_uuid2'], | ||
} | ||
|
||
expect(mergeSectorAndSubSectorParams(reqBody)).to.deep.equal({ | ||
...basicRequestBody, | ||
sector_descends: ['sector_uuid1', 'sector_uuid2'], | ||
}) | ||
}) | ||
|
||
it('should include just the sub sector params if there are not any sector params', () => { | ||
const reqBody = { | ||
...basicRequestBody, | ||
sub_sector_descends: ['sub_sector_uuid1', 'sub_sector_uuid2'], | ||
} | ||
|
||
expect(mergeSectorAndSubSectorParams(reqBody)).to.deep.equal({ | ||
...basicRequestBody, | ||
sector_descends: ['sub_sector_uuid1', 'sub_sector_uuid2'], | ||
}) | ||
}) | ||
|
||
it('should not include any sector or sub sector params if neither are present', () => { | ||
expect(mergeSectorAndSubSectorParams(basicRequestBody)).to.deep.equal( | ||
basicRequestBody | ||
) | ||
}) | ||
}) |