-
Notifications
You must be signed in to change notification settings - Fork 20
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'main' into yus/rn-sdk-auto-env
- Loading branch information
Showing
10 changed files
with
164 additions
and
92 deletions.
There are no files selected for viewing
108 changes: 58 additions & 50 deletions
108
packages/shared/common/__tests__/options/ApplicationTags.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 |
---|---|---|
@@ -1,82 +1,90 @@ | ||
import ApplicationTags from '../../src/options/ApplicationTags'; | ||
import { logger } from '@launchdarkly/private-js-mocks'; | ||
|
||
function makeLogger() { | ||
return { | ||
error: jest.fn(), | ||
warn: jest.fn(), | ||
info: jest.fn(), | ||
debug: jest.fn(), | ||
}; | ||
} | ||
import ApplicationTags from '../../src/options/ApplicationTags'; | ||
|
||
describe.each([ | ||
[ | ||
{ application: { id: 'is-valid', version: 'also-valid' }, logger: makeLogger() }, | ||
{ application: { id: 'is-valid', version: 'also-valid' }, logger }, | ||
'application-id/is-valid application-version/also-valid', | ||
[], | ||
], | ||
[{ application: { id: 'is-valid' }, logger: makeLogger() }, 'application-id/is-valid', []], | ||
[ | ||
{ application: { version: 'also-valid' }, logger: makeLogger() }, | ||
'application-version/also-valid', | ||
{ | ||
application: { | ||
id: 'is-valid', | ||
version: 'also-valid', | ||
name: 'test-app-1', | ||
versionName: 'test-version-1', | ||
}, | ||
logger, | ||
}, | ||
'application-id/is-valid application-name/test-app-1 application-version/also-valid application-version-name/test-version-1', | ||
[], | ||
], | ||
[{ application: {}, logger: makeLogger() }, undefined, []], | ||
[{ logger: makeLogger() }, undefined, []], | ||
[undefined, undefined, undefined], | ||
[{ application: { id: 'is-valid' }, logger }, 'application-id/is-valid', []], | ||
[{ application: { version: 'also-valid' }, logger }, 'application-version/also-valid', []], | ||
[{ application: {}, logger }, undefined, []], | ||
[{ logger }, undefined, []], | ||
[undefined, undefined, []], | ||
|
||
// Above ones are 'valid' cases. Below are invalid. | ||
[{ application: { id: 'bad tag' }, logger }, undefined, [/Config option "application.id" must/]], | ||
[ | ||
{ application: { id: 'bad tag' }, logger: makeLogger() }, | ||
undefined, | ||
[{ level: 'warn', matches: /Config option "application.id" must/ }], | ||
{ application: { id: 'bad tag', version: 'good-tag' }, logger }, | ||
'application-version/good-tag', | ||
[/Config option "application.id" must/], | ||
], | ||
[ | ||
{ application: { id: 'bad tag', version: 'good-tag' }, logger: makeLogger() }, | ||
'application-version/good-tag', | ||
[{ level: 'warn', matches: /Config option "application.id" must/ }], | ||
{ | ||
application: { id: 'bad tag', version: 'good-tag', name: '', versionName: 'test-version-1' }, | ||
logger, | ||
}, | ||
'application-version/good-tag application-version-name/test-version-1', | ||
[/Config option "application.id" must/, /Config option "application.name" must/], | ||
], | ||
[ | ||
{ application: { id: 'bad tag', version: 'also bad' }, logger: makeLogger() }, | ||
{ | ||
application: { | ||
id: 'bad tag', | ||
version: 'also bad', | ||
name: 'invalid name', | ||
versionName: 'invalid version name', | ||
}, | ||
logger, | ||
}, | ||
undefined, | ||
[ | ||
{ level: 'warn', matches: /Config option "application.id" must/ }, | ||
{ level: 'warn', matches: /Config option "application.version" must/ }, | ||
/Config option "application.id" must/, | ||
/Config option "application.version" must/, | ||
/Config option "application.name" must/, | ||
/Config option "application.versionName" must/, | ||
], | ||
], | ||
// Bad tags and no logger. | ||
[ | ||
{ application: { id: 'bad tag', version: 'also bad' }, logger: undefined }, | ||
undefined, | ||
undefined, | ||
], | ||
])('given application tags configurations %p', (config, result, logs) => { | ||
[{ application: { id: 'bad tag', version: 'also bad' }, logger: undefined }, undefined, []], | ||
])('given application tags configurations %j', (config, result, warnings: RegExp[]) => { | ||
describe('when getting tag values', () => { | ||
// @ts-ignore | ||
const tags = new ApplicationTags(config); | ||
let tags: ApplicationTags; | ||
|
||
beforeEach(() => { | ||
// @ts-ignore | ||
tags = new ApplicationTags(config); | ||
}); | ||
|
||
afterEach(() => { | ||
jest.resetAllMocks(); | ||
}); | ||
|
||
it('produces the correct tag values', () => { | ||
expect(tags.value).toEqual(result); | ||
}); | ||
|
||
it('logs issues it encounters', () => { | ||
expect(config?.logger?.warn.mock.calls.length).toEqual(logs?.length); | ||
it(`logs issues it encounters for ${JSON.stringify(config)}`, () => { | ||
expect(logger.warn).toHaveBeenCalledTimes(warnings.length); | ||
|
||
if (logs) { | ||
const expected = [...logs]; | ||
config!.logger!.warn.mock.calls.forEach((call) => { | ||
const index = expected.findIndex((expectedLog) => call[0].match(expectedLog.matches)); | ||
if (index < 0) { | ||
throw new Error(`Did not find expectation for ${call[0]}`); | ||
} | ||
expected.splice(index, 1); | ||
}); | ||
if (expected.length) { | ||
throw new Error( | ||
`Did not find expected messages: ${expected.map((item) => item.matches.toString())}`, | ||
); | ||
} | ||
} | ||
warnings.forEach((regExp) => { | ||
expect(logger.warn).toHaveBeenCalledWith(expect.stringMatching(regExp)); | ||
}); | ||
}); | ||
}); | ||
}); |
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
Oops, something went wrong.