Skip to content

Commit

Permalink
fix(tests): cover pairs to map helper
Browse files Browse the repository at this point in the history
  • Loading branch information
ssube committed Oct 4, 2019
1 parent 6a52c2b commit f530266
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 8 deletions.
3 changes: 1 addition & 2 deletions src/interval/MessageInterval.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,7 @@ export class MessageInterval extends BaseInterval<MessageIntervalData> {
public async start() {
await super.start();

const transforms: Array<ServiceDefinition<TransformData>> = this.data.transforms;
for (const def of transforms) {
for (const def of this.data.transforms) {
const transform = await this.services.createService<Transform, TransformData>(def);
this.transforms.push(transform);
}
Expand Down
8 changes: 3 additions & 5 deletions src/utils/Map.ts
Original file line number Diff line number Diff line change
Expand Up @@ -124,12 +124,10 @@ export interface NameValuePair<TVal> {
value: TVal;
}

export function pairsToMap<TVal>(pairs: Array<NameValuePair<TVal>> | undefined): Map<string, TVal> {
export function pairsToMap<TVal>(pairs: Array<NameValuePair<TVal>>): Map<string, TVal> {
const map = new Map();
if (doesExist(pairs)) {
for (const p of pairs) {
map.set(p.name, p.value);
}
for (const p of pairs) {
map.set(p.name, p.value);
}
return map;
}
Expand Down
2 changes: 2 additions & 0 deletions test/error/TestError.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import { MimeTypeError } from '../../src/error/MimeTypeError';
import { MissingKeyError } from '../../src/error/MissingKeyError';
import { NotFoundError } from '../../src/error/NotFoundError';
import { NotImplementedError } from '../../src/error/NotImplementedError';
import { NotInitializedError } from '../../src/error/NotInitializedError';
import { SchemaError } from '../../src/error/SchemaError';
import { SessionRequiredError } from '../../src/error/SessionRequiredError';
import { TimeoutError } from '../../src/error/TimeoutError';
Expand All @@ -15,6 +16,7 @@ const errors = [
MissingKeyError,
NotFoundError,
NotImplementedError,
NotInitializedError,
SchemaError,
SessionRequiredError,
TimeoutError,
Expand Down
12 changes: 11 additions & 1 deletion test/utils/TestMap.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { expect } from 'chai';

import { NotFoundError } from '../../src/error/NotFoundError';
import { getHead, getHeadOrDefault, getOrDefault, makeDict, makeMap, mustGet } from '../../src/utils/Map';
import { getHead, getHeadOrDefault, getOrDefault, makeDict, makeMap, mustGet, pairsToMap } from '../../src/utils/Map';
import { describeLeaks, itLeaks } from '../helpers/async';

const DEFAULT_VALUE = 'default';
Expand Down Expand Up @@ -79,4 +79,14 @@ describeLeaks('map utils', async () => {
xit('should return the default for nil values');
xit('should return falsy values for existing keys');
});

describe('pairs to map helper', () => {
it('should convert pairs', () => {
const result = pairsToMap([{
name: 'foo',
value: 3,
}]);
expect(result.get('foo')).to.equal(3);
});
});
});

0 comments on commit f530266

Please sign in to comment.