Skip to content

Commit

Permalink
feat!: pickFor now every time returns EnvPicker
Browse files Browse the repository at this point in the history
  • Loading branch information
allohamora committed Apr 11, 2023
1 parent 8ee3e0d commit e688443
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 9 deletions.
14 changes: 7 additions & 7 deletions __tests__/unit/env.manager.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,15 +37,15 @@ describe('EnvManager', () => {

describe('pickFor', () => {
it('returns values', () => {
expect(env.pickFor({ test: 'EMAIL' })?.value()).toBe(envStub.EMAIL);
expect(env.pickFor({ test: 'INTEGER' })?.value()).toBe(envStub.INTEGER);
expect(env.pickFor({ test: 'EMAIL' }).value()).toBe(envStub.EMAIL);
expect(env.pickFor({ test: 'INTEGER' }).value()).toBe(envStub.INTEGER);

expect(env.pickFor({ production: 'EMAIL' })?.value()).toEqual(undefined);
expect(env.pickFor({ production: 'INTEGER' })?.value()).toEqual(undefined);
expect(env.pickFor({ production: 'EMAIL' }).value()).toEqual(undefined);
expect(env.pickFor({ production: 'INTEGER' }).value()).toEqual(undefined);

expect(env.pickFor({ test: 'EMPTY_STRING' })?.value()).toEqual(undefined);
expect(env.pickFor({ test: 'SPACE_STRING' })?.value()).toEqual(undefined);
expect(env.pickFor({ test: 'OPTIONAL' })?.value()).toEqual(undefined);
expect(env.pickFor({ test: 'EMPTY_STRING' }).value()).toEqual(undefined);
expect(env.pickFor({ test: 'SPACE_STRING' }).value()).toEqual(undefined);
expect(env.pickFor({ test: 'OPTIONAL' }).value()).toEqual(undefined);
});
});

Expand Down
4 changes: 2 additions & 2 deletions src/env/env.manager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -57,11 +57,11 @@ export class EnvManager<E extends string, C extends BaseConfig = BaseConfig> ext
return this.pick(key) as EnvPicker<E, C[K]>;
}

public pickFor<K extends keyof C>(envRecord: AtLeastOne<Record<E, K>>): undefined | EnvPicker<E, C[K] | undefined> {
public pickFor<K extends keyof C>(envRecord: AtLeastOne<Record<E, K>>): EnvPicker<E, C[K] | undefined> {
const key = envRecord[this.nodeEnv as E] as string | undefined;

if (!key) {
return;
return new EnvPicker(undefined, this.nodeEnv) as EnvPicker<E, undefined>;
}

return this.pick(key) as EnvPicker<E, C[K] | undefined>;
Expand Down

0 comments on commit e688443

Please sign in to comment.