Skip to content

Commit 14cb01f

Browse files
committed
added file access error test
1 parent d4a8054 commit 14cb01f

File tree

1 file changed

+11
-1
lines changed

1 file changed

+11
-1
lines changed

spec/ApiMailAdapter.spec.js

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -630,7 +630,7 @@ describe('ApiMailAdapter', () => {
630630
expect(htmlSpyData.toString('utf8')).toEqual(htmlFileData.toString('utf8'));
631631
});
632632

633-
it('falls back to default file if there is no language or locale match', async function () {
633+
it('falls back to default file if there is no language or locale match', async () => {
634634
// Pretend that there are no files in folders `de-AT` and `de`
635635
spyOn(adapter, '_fileExists').and.callFake(async (path) => {
636636
return !/\/templates\/de(-AT)?\//.test(path);
@@ -650,6 +650,16 @@ describe('ApiMailAdapter', () => {
650650
expect(htmlSpyData.toString('utf8')).toEqual(htmlFileData.toString('utf8'));
651651
});
652652

653+
it('falls back to default file if file reading throws', async () => {
654+
const getLocalizedFilePathSpy = spyOn(adapter, '_getLocalizedFilePath').and.callThrough();
655+
spyOn(fs, 'access').and.callFake(async () => {
656+
throw 'Test file access error';
657+
});
658+
await adapter._createApiData(options);
659+
const file = await getLocalizedFilePathSpy.calls.all()[0].returnValue;
660+
expect(file).toMatch(options.template.subjectPath);
661+
});
662+
653663
it('makes user locale available in API callback', async () => {
654664
const locale = await options.template.localeCallback();
655665
const email = {

0 commit comments

Comments
 (0)