-
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.
AUT-3779: Extract template selection logic to function with tests
Introduces the getAccountNotFoundTemplate function which replicates existing template selection logic previously included in the controller and calls getChannelSpecificTemplate. I've opted to do this because the additional requirement to select a template that is appropriate for the channel will introduce additional logic. My sense is that two functions (one that selects the web template and calls another to retrieve the mobile equivalent of that template) is easier to understand and test.
- Loading branch information
Showing
3 changed files
with
58 additions
and
11 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
16 changes: 16 additions & 0 deletions
16
src/components/account-not-found/get-account-not-found-web-template.ts
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,16 @@ | ||
import { SERVICE_TYPE } from "../../app.constants"; | ||
|
||
export function getAccountNotFoundWebTemplate( | ||
isOneLoginService: boolean, | ||
serviceType: string | ||
): string { | ||
if (isOneLoginService === true) { | ||
return "account-not-found/index-one-login.njk"; | ||
} | ||
|
||
if (serviceType === SERVICE_TYPE.OPTIONAL) { | ||
return "account-not-found/index-optional.njk"; | ||
} | ||
|
||
return "account-not-found/index-mandatory.njk"; | ||
} |
32 changes: 32 additions & 0 deletions
32
src/components/account-not-found/tests/get-account-not-found-web-template.test.ts
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,32 @@ | ||
import { expect } from "chai"; | ||
import { describe } from "mocha"; | ||
import { getAccountNotFoundWebTemplate } from "../get-account-not-found-web-template"; | ||
import { SERVICE_TYPE } from "../../../app.constants"; | ||
|
||
describe("getAccountNotFoundWebTemplate", () => { | ||
describe("when isOneLoginService is true", () => { | ||
it("should always return 'account-not-found/index-one-login.njk'", () => { | ||
[SERVICE_TYPE.OPTIONAL, SERVICE_TYPE.MANDATORY].forEach((i) => { | ||
expect(getAccountNotFoundWebTemplate(true, i)).to.equal( | ||
"account-not-found/index-one-login.njk" | ||
); | ||
}); | ||
}); | ||
}); | ||
|
||
describe("when isOneLoginService is false", () => { | ||
it("should return 'account-not-found/index-optional.njk' when serviceType is equal to SERVICE_TYPE.OPTIONAL", () => { | ||
expect( | ||
getAccountNotFoundWebTemplate(false, SERVICE_TYPE.OPTIONAL) | ||
).to.equal("account-not-found/index-optional.njk"); | ||
}); | ||
|
||
it("should return 'account-not-found/index-mandatory.njk' when serviceType is not equal to SERVICE_TYPE.OPTIONAL", () => { | ||
[SERVICE_TYPE.MANDATORY, ""].forEach((i) => { | ||
expect(getAccountNotFoundWebTemplate(false, i)).to.equal( | ||
"account-not-found/index-mandatory.njk" | ||
); | ||
}); | ||
}); | ||
}); | ||
}); |