Skip to content
This repository has been archived by the owner on Jul 20, 2021. It is now read-only.

Commit

Permalink
feat(versioned-configs): add version to serialized config
Browse files Browse the repository at this point in the history
  • Loading branch information
Per Kristian Kummermo committed Dec 3, 2018
1 parent 609eab5 commit 6985bb9
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 2 deletions.
6 changes: 4 additions & 2 deletions src/DataMapperChain.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@ import { Mappers } from "./Mappers";
import { IDataValue, IMapper, IMapperConfig, IOutputType } from "./Typings";

const { Base64, Chunk, FromJSON, HexToFloat, HexToInt, Offset } = Mappers;
// tslint:disable-next-line:no-var-requires
const { version } = require("../package.json");

class MapperMock implements IMapper {
initParams: any = {};
Expand Down Expand Up @@ -71,14 +73,14 @@ describe("Data mapper chain", () => {
dataMapperChain.mappers = [];

const serializedConfig = dataMapperChain.serializeConfig();
expect(serializedConfig).toBe(`{"name":"Test","mappers":[]}`);
expect(serializedConfig).toBe(`{"name":"Test","version":"${version}","mappers":[]}`);
});

it("should correctly serialize with mapper", () => {
dataMapperChain.addMapper(new MapperMock());

const serializedConfig = dataMapperChain.serializeConfig();
expect(serializedConfig).toBe(`{"name":"","mappers":[{"id":"MOCK","params":{"p1":1,"p2":"2"}}]}`);
expect(serializedConfig).toBe(`{"name":"","version":"${version}","mappers":[{"id":"MOCK","params":{"p1":1,"p2":"2"}}]}`);
});

it("should correctly deserialize with no mappers", () => {
Expand Down
2 changes: 2 additions & 0 deletions src/DataMapperChain.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import { IBase64Config, IChunkConfig, IFromJSONConfig, IHexToFloatConfig, IHexTo
import { AVAILABLE_MAPPERS_TYPES, Mappers } from "./Mappers";
import { IDataValue, IMapper, IMapperConfig, IMapperType } from "./Typings";

const CURRENT_VERSION = "0.6.0";
const { Base64, Chunk, FromJSON, HexToFloat, HexToInt, Offset } = Mappers;

/**
Expand Down Expand Up @@ -63,6 +64,7 @@ export class DataMapperChain {
serializeConfig(): string {
return JSON.stringify({
name: this.name,
version: CURRENT_VERSION,
mappers: this.mappers.map((mapper) => {
return mapper.config();
}),
Expand Down

0 comments on commit 6985bb9

Please sign in to comment.