Skip to content

Commit

Permalink
Merge pull request #104 from sima-land/38-examples-bun
Browse files Browse the repository at this point in the history
Шаг 57 #38
  • Loading branch information
krutoo committed Feb 29, 2024
2 parents e30483d + 0b79b7e commit c3f0b61
Show file tree
Hide file tree
Showing 2 changed files with 54 additions and 0 deletions.
45 changes: 45 additions & 0 deletions src/preset/isomorphic/utils/__test__/index.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -131,6 +131,51 @@ describe('HttpApiHostPool', () => {

expect(pool.get('foobar', { absolute: true })).toEqual('http://www.foobar.com');
});

it('getAll() should return all hosts', () => {
const source = new Env({
API_HOST_FOO: 'http://www.foo.com',
API_HOST_BAR: 'http://www.bar.com',
API_HOST_BAZ: 'http://www.baz.com',
});

const pool = new HttpApiHostPool(
{
foo: 'API_HOST_FOO',
bar: 'API_HOST_BAR',
baz: 'API_HOST_BAZ',
},
source,
);

expect(pool.getAll()).toEqual({
foo: 'http://www.foo.com',
bar: 'http://www.bar.com',
baz: 'http://www.baz.com',
});
});

it('getAll(keys) should return hosts for keys', () => {
const source = new Env({
API_HOST_FOO: 'http://www.foo.com',
API_HOST_BAR: 'http://www.bar.com',
API_HOST_BAZ: 'http://www.baz.com',
});

const pool = new HttpApiHostPool(
{
foo: 'API_HOST_FOO',
bar: 'API_HOST_BAR',
baz: 'API_HOST_BAZ',
},
source,
);

expect(pool.getAll(['foo', 'baz'])).toEqual({
foo: 'http://www.foo.com',
baz: 'http://www.baz.com',
});
});
});

describe('severityFromStatus', () => {
Expand Down
9 changes: 9 additions & 0 deletions src/preset/isomorphic/utils/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,15 @@ export class HttpApiHostPool<Key extends string> implements StrictMap<Key> {

return value;
}

/**
* Возвращает объект в котором ключи - переданные имена хостов а значения - хосты.
* @param keys Названия хостов.
* @return Объект.
*/
getAll(keys: Key[] = Object.keys(this.map) as Key[]): Record<Key, string> {
return Object.fromEntries(keys.map(key => [key, this.get(key)])) as Record<Key, string>;
}
}

/**
Expand Down

0 comments on commit c3f0b61

Please sign in to comment.