Skip to content

Commit

Permalink
add unit test for throws LyraConfigReadingError
Browse files Browse the repository at this point in the history
  • Loading branch information
amerharb committed Dec 15, 2023
1 parent 32bbccd commit b3580d9
Showing 1 changed file with 48 additions and 2 deletions.
50 changes: 48 additions & 2 deletions webapp/src/utils/config.spec.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import { LyraConfigReadingError } from '@/errors';
import mock from 'mock-fs';
import { describe, expect, it } from '@jest/globals';
import LyraConfig, { MessageKind } from './config';
Expand Down Expand Up @@ -47,7 +48,7 @@ describe('LyraConfig', () => {
);
});

it('read baseBranch', async () => {
it('reads baseBranch', async () => {
mock({
'/path/to/repo/lyra.yml': [
'baseBranch: branch1',
Expand All @@ -65,7 +66,7 @@ describe('LyraConfig', () => {
expect(config.baseBranch).toEqual('branch1');
});

it('read more than one projects', async () => {
it('reads more than one projects', async () => {
mock({
'/path/to/repo/lyra.yml': [
'projects:',
Expand Down Expand Up @@ -100,5 +101,50 @@ describe('LyraConfig', () => {
);
expect(config.projects[1].messageKind).toEqual(MessageKind.TS);
});

describe('throw LyraConfigReadingError for invalid content or file not found', () => {
it('throws for empty file', async () => {
expect.assertions(1);
mock({ '/path/to/repo/lyra.yml': '' });

const readFromDirFunc = () => LyraConfig.readFromDir('/path/to/repo');
await expect(readFromDirFunc()).rejects.toThrow(LyraConfigReadingError);
});

it('throws for missing messages path', async () => {
expect.assertions(1);
mock({
'/path/to/repo/lyra.yml': [
'baseBranch: branch1',
'projects:',
'- path: subproject',
' messages:',
' format: ts',
' translations:',
' path: anyValue',
].join('\n'),
});
const readFromDirFunc = () => LyraConfig.readFromDir('/path/to/repo');
await expect(readFromDirFunc()).rejects.toThrow(LyraConfigReadingError);
});

it('throws for file not found', async () => {
expect.assertions(1);
mock({
'/path/to/repo/xxx.yml': [
'baseBranch: branch1',
'projects:',
'- path: subproject',
' messages:',
' format: ts',
' path: anyValue',
' translations:',
' path: anyValue',
].join('\n'),
});
const readFromDirFunc = () => LyraConfig.readFromDir('/path/to/repo');
await expect(readFromDirFunc()).rejects.toThrow(LyraConfigReadingError);
});
});
});
});

0 comments on commit b3580d9

Please sign in to comment.