Skip to content

Commit f13ff6f

Browse files
committed
feat: tests for $extendsSelf with object options
1 parent 45a57c8 commit f13ff6f

File tree

1 file changed

+55
-1
lines changed

1 file changed

+55
-1
lines changed

app-config-extensions/src/extends-directive.test.ts

Lines changed: 55 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -259,7 +259,7 @@ describe('$extendsSelf directive', () => {
259259
await expect(source.read([extendsSelfDirective()])).rejects.toThrow();
260260
});
261261

262-
it('fails when $extendsSelf selector is not a string', async () => {
262+
it('fails when $extendsSelf selector is invalid object', async () => {
263263
const source = new LiteralSource({
264264
foo: {
265265
$extendsSelf: {},
@@ -269,6 +269,60 @@ describe('$extendsSelf directive', () => {
269269
await expect(source.read([extendsSelfDirective()])).rejects.toThrow();
270270
});
271271

272+
it('resolves with select option', async () => {
273+
const source = new LiteralSource({
274+
foo: {
275+
$extendsSelf: {
276+
select: 'bar',
277+
},
278+
},
279+
bar: 42,
280+
});
281+
282+
expect(await source.readToJSON([extendsSelfDirective()])).toEqual({ foo: 42, bar: 42 });
283+
});
284+
285+
it('resolves with select and env option', async () => {
286+
const source = new LiteralSource({
287+
foo: {
288+
$extendsSelf: {
289+
select: 'bar',
290+
env: 'qa',
291+
},
292+
},
293+
bar: {
294+
$substitute: '$APP_CONFIG_ENV',
295+
},
296+
});
297+
298+
expect(await source.readToJSON([extendsSelfDirective(), substituteDirective()])).toEqual({
299+
foo: 'qa',
300+
bar: 'test',
301+
});
302+
});
303+
304+
it('resolves with select and env option', async () => {
305+
const source = new LiteralSource({
306+
foo: {
307+
$extendsSelf: {
308+
select: 'bar',
309+
env: 'qa',
310+
},
311+
},
312+
bar: {
313+
$env: {
314+
default: 42,
315+
qa: 88,
316+
},
317+
},
318+
});
319+
320+
expect(await source.readToJSON([extendsSelfDirective(), envDirective()])).toEqual({
321+
foo: 88,
322+
bar: 42,
323+
});
324+
});
325+
272326
it('resolves a simple $extendsSelf selector', async () => {
273327
const source = new LiteralSource({
274328
foo: {

0 commit comments

Comments
 (0)