-
Notifications
You must be signed in to change notification settings - Fork 38
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(modal): introduce the backend for announcement modal
Allow a new env var - `USER_ANNOUNCEMENT` - to be specified at runtime, parsed into a simple JSON payload to be at `/api/user/announcement` - Declare `USER_ANNOUNCEMENT` at config, to be parsed into `userModal` - Inject `config.userAnnouncement` into UserController via inversify - Expose this via `/api/user/announcement` - Provide coverage tests that verify parsing and serving
- Loading branch information
Showing
10 changed files
with
152 additions
and
2 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
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
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,27 @@ | ||
export function parseAnnouncementString( | ||
announcementString?: string, | ||
): { | ||
message?: string | ||
title?: string | ||
subtitle?: string | ||
url?: string | ||
image?: string | ||
} { | ||
if (!announcementString) { | ||
return { | ||
message: undefined, | ||
title: undefined, | ||
subtitle: undefined, | ||
url: undefined, | ||
image: undefined, | ||
} | ||
} | ||
const [message, title, subtitle, url, image] = ( | ||
announcementString || '' | ||
).split(';') | ||
return { message, title, subtitle, url, image } | ||
} | ||
|
||
export default { | ||
parseAnnouncementString, | ||
} |
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,59 @@ | ||
import { parseAnnouncementString } from '../../../src/server/util/modal' | ||
|
||
describe('parseAnnouncementString', () => { | ||
it('has all undefined for undefined', () => { | ||
expect(parseAnnouncementString(undefined)).toStrictEqual({ | ||
message: undefined, | ||
title: undefined, | ||
subtitle: undefined, | ||
url: undefined, | ||
image: undefined, | ||
}) | ||
}) | ||
|
||
it('has all undefined message for blank', () => { | ||
expect(parseAnnouncementString('')).toStrictEqual({ | ||
message: undefined, | ||
title: undefined, | ||
subtitle: undefined, | ||
url: undefined, | ||
image: undefined, | ||
}) | ||
}) | ||
|
||
it('has only message for message', () => { | ||
expect(parseAnnouncementString('message')).toStrictEqual({ | ||
message: 'message', | ||
title: undefined, | ||
subtitle: undefined, | ||
url: undefined, | ||
image: undefined, | ||
}) | ||
}) | ||
|
||
it('has blank url and subtitle if not specified but image specified', () => { | ||
expect( | ||
parseAnnouncementString('message;title;;;/favicon.ico'), | ||
).toStrictEqual({ | ||
message: 'message', | ||
title: 'title', | ||
subtitle: '', | ||
url: '', | ||
image: '/favicon.ico', | ||
}) | ||
}) | ||
|
||
it('has fields populated if fields populated', () => { | ||
expect( | ||
parseAnnouncementString( | ||
'message;title;subtitle;https://go.gov.sg/;/favicon.ico', | ||
), | ||
).toStrictEqual({ | ||
message: 'message', | ||
title: 'title', | ||
subtitle: 'subtitle', | ||
url: 'https://go.gov.sg/', | ||
image: '/favicon.ico', | ||
}) | ||
}) | ||
}) |