Skip to content

Commit

Permalink
Merge branch 'release/0.7.0'
Browse files Browse the repository at this point in the history
  • Loading branch information
allohamora committed Jul 27, 2023
2 parents eed80c6 + d3ef413 commit 59cdc1a
Show file tree
Hide file tree
Showing 10 changed files with 320 additions and 221 deletions.
8 changes: 8 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,14 @@

All notable changes to this project will be documented in this file. See [standard-version](https://github.com/conventional-changelog/standard-version) for commit guidelines.

## [0.7.0](https://github.com/allohamora/config-manager/compare/0.6.0...0.7.0) (2023-07-27)

### Features

- add rest to envRecord ([2d57b5d](https://github.com/allohamora/config-manager/commit/2d57b5d4e9ce2555cafd5b302ce0b4195c1b4a83))
- improve defaultFor with rest return value ([304530d](https://github.com/allohamora/config-manager/commit/304530d2106ac0575fe06cc8a532be48e441d924))
- improve orThrow methods typing ([d7f7590](https://github.com/allohamora/config-manager/commit/d7f7590e3ee04eef31edeb028752105056982346))

## [0.6.0](https://github.com/allohamora/config-manager/compare/0.5.2...0.6.0) (2023-04-13)

### ⚠ BREAKING CHANGES
Expand Down
55 changes: 55 additions & 0 deletions __tests__/unit/env.manager.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,21 @@ describe('EnvManager', () => {
expect(env.pickFor({ test: 'SPACE_STRING' }).value()).toEqual(undefined);
expect(env.pickFor({ test: 'OPTIONAL' }).value()).toEqual(undefined);
});

it('returns default values', () => {
expect(env.pickFor({ production: 'INTEGER', rest: 'EMAIL' }).value()).toBe(envStub.EMAIL);
expect(env.pickFor({ production: 'EMAIL', rest: 'INTEGER' }).value()).toBe(envStub.INTEGER);
});

it('returns environment values instead of default', () => {
expect(env.pickFor({ test: 'INTEGER', rest: 'EMAIL' }).value()).toBe(envStub.INTEGER);
expect(env.pickFor({ test: 'EMAIL', rest: 'INTEGER' }).value()).toBe(envStub.EMAIL);
});

it('returns undefined', () => {
expect(env.pickFor({ production: 'INTEGER', rest: '__TEST__' }).value()).toBe(undefined);
expect(env.pickFor({ production: 'EMAIL', rest: '__TEST__' }).value()).toBe(undefined);
});
});

describe('pickForOrThrow', () => {
Expand All @@ -55,13 +70,26 @@ describe('EnvManager', () => {
expect(env.pickForOrThrow({ test: 'INTEGER' }).value()).toBe(envStub.INTEGER);
});

it('returns default values', () => {
expect(env.pickForOrThrow({ production: 'INTEGER', rest: 'EMAIL' }).value()).toBe(envStub.EMAIL);
expect(env.pickForOrThrow({ production: 'EMAIL', rest: 'INTEGER' }).value()).toBe(envStub.INTEGER);
});

it('returns environment values instead of default', () => {
expect(env.pickForOrThrow({ test: 'INTEGER', rest: 'EMAIL' }).value()).toBe(envStub.INTEGER);
expect(env.pickForOrThrow({ test: 'EMAIL', rest: 'INTEGER' }).value()).toBe(envStub.EMAIL);
});

it('throws errors', () => {
expect(() => env.pickForOrThrow({ test: 'EMPTY_STRING' })).toThrowError();
expect(() => env.pickForOrThrow({ test: 'SPACE_STRING' })).toThrowError();
expect(() => env.pickForOrThrow({ test: 'OPTIONAL' })).toThrowError();

expect(() => env.pickForOrThrow({ production: 'EMAIL' })).toThrowError();
expect(() => env.pickForOrThrow({ production: 'production' })).toThrowError();

expect(() => env.pickForOrThrow({ production: 'EMAIL', rest: '__TEST__' })).toThrowError();
expect(() => env.pickForOrThrow({ production: 'EMAIL', rest: 'rest' })).toThrowError();
});
});

Expand All @@ -77,6 +105,21 @@ describe('EnvManager', () => {
expect(env.getFor({ test: 'SPACE_STRING' })).toEqual(envStub.SPACE_STRING);
expect(env.getFor({ test: 'OPTIONAL' })).toEqual(undefined);
});

it('returns default values', () => {
expect(env.getFor({ production: 'INTEGER', rest: 'EMAIL' })).toBe(envStub.EMAIL);
expect(env.getFor({ production: 'EMAIL', rest: 'INTEGER' })).toBe(envStub.INTEGER);
});

it('returns environment values instead of default', () => {
expect(env.getFor({ test: 'INTEGER', rest: 'EMAIL' })).toBe(envStub.INTEGER);
expect(env.getFor({ test: 'EMAIL', rest: 'INTEGER' })).toBe(envStub.EMAIL);
});

it('returns undefined', () => {
expect(env.getFor({ production: 'INTEGER', rest: '__TEST__' })).toBe(undefined);
expect(env.getFor({ production: 'EMAIL', rest: '__TEST__' })).toBe(undefined);
});
});

describe('getForOrThrow', () => {
Expand All @@ -87,10 +130,22 @@ describe('EnvManager', () => {
expect(env.getForOrThrow({ test: 'SPACE_STRING' })).toEqual(envStub.SPACE_STRING);
});

it('returns default values', () => {
expect(env.getForOrThrow({ production: 'INTEGER', rest: 'EMAIL' })).toBe(envStub.EMAIL);
expect(env.getForOrThrow({ production: 'EMAIL', rest: 'INTEGER' })).toBe(envStub.INTEGER);
});

it('returns environment values instead of default', () => {
expect(env.getForOrThrow({ test: 'INTEGER', rest: 'EMAIL' })).toBe(envStub.INTEGER);
expect(env.getForOrThrow({ test: 'EMAIL', rest: 'INTEGER' })).toBe(envStub.EMAIL);
});

it('throws errors', () => {
expect(() => env.getForOrThrow({ test: 'OPTIONAL' })).toThrowError();
expect(() => env.getForOrThrow({ test: 'OPTIONAL', rest: '__TEST__' })).toThrowError();
expect(() => env.getForOrThrow({ production: 'EMAIL' })).toThrowError();
expect(() => env.getForOrThrow({ production: 'production' })).toThrowError();
expect(() => env.getForOrThrow({ production: 'production', rest: 'rest' })).toThrowError();
});
});
});
16 changes: 15 additions & 1 deletion __tests__/unit/env.picker.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,17 @@ describe('EnvPicker', () => {
expect(new EnvPicker(null as string | null, 'test').defaultFor({ test: '123' }).value()).toBe('123');
});

it('sets rest values', () => {
expect(
new EnvPicker(undefined as string | undefined, 'test' as string)
.defaultFor({ production: '123', rest: '321' })
.value(),
).toBe('321');
expect(
new EnvPicker(null as string | null, 'test' as string).defaultFor({ production: '123', rest: '321' }).value(),
).toBe('321');
});

it('doesn`t set default value for environment', () => {
expect(
new EnvPicker(undefined as string | undefined, 'test' as string).defaultFor({ production: '123' }).value(),
Expand All @@ -29,14 +40,17 @@ describe('EnvPicker', () => {
).toBe(undefined);

expect(new EnvPicker(false as boolean | undefined, 'test').defaultFor({ test: true }).value()).toBe(false);
expect(new EnvPicker('', 'test').defaultFor({ test: '123' }).value()).toBe('');
expect(new EnvPicker('' as string | undefined, 'test').defaultFor({ test: '123' }).value()).toBe('');
});
});

describe('map', () => {
it('maps state', () => {
expect(new EnvPicker('123', 'test').map(Number).value()).toBe(123);
expect(new EnvPicker(undefined as string | undefined, 'test').default('123').map(Number).value()).toBe(123);
expect(
new EnvPicker(undefined as string | undefined, 'test').defaultFor({ rest: '123' }).map(Number).value(),
).toBe(123);
expect(new EnvPicker('false', 'test').default('123').map(JSON.parse).value()).toBe(false);
expect(new EnvPicker(undefined as string | undefined, 'test').map((state) => !!state).value()).toBe(false);
});
Expand Down
Loading

0 comments on commit 59cdc1a

Please sign in to comment.