Skip to content

Commit

Permalink
RELATED: RAIL-730 Remove backward compatible CatalogHelper code (comp…
Browse files Browse the repository at this point in the history
…atible with old version gdc-catalog-export tool)
  • Loading branch information
David Ocetnik committed Apr 9, 2018
1 parent e25f5a8 commit 68796d8
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 52 deletions.
23 changes: 3 additions & 20 deletions src/helpers/CatalogHelper.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,6 @@ export interface IDataSet {
}

export interface ICatalog {
metrics?: { [key: string]: IIdentifierWithTags };
measures?: { [key: string]: IIdentifierWithTags };
visualizations: { [key: string]: IIdentifierWithTags };
attributes: IAttrs;
Expand Down Expand Up @@ -57,26 +56,18 @@ export default class CatalogHelper {
public dateDataSets: { [key: string]: IDataSet };

constructor(catalog: ICatalog) {
this.measures = catalog.metrics || catalog.measures;
this.measures = catalog.measures;
this.visualizations = catalog.visualizations;
this.attributes = catalog.attributes;
this.dateDataSets = catalog.dateDataSets;
}

public metric(name: string): string {
return this.getMeasure(name);
}

public measure(name: string): string {
return this.getMeasure(name);
}

public metricTags(name: string): string {
return this.getMeasureTags(name);
return get<CatalogHelper, string>(this, ['measures', name, 'identifier']);
}

public measureTags(name: string): string {
return this.getMeasureTags(name);
return get<CatalogHelper, string>(this, ['measures', name, 'tags']);
}

public visualization(name: string): string {
Expand Down Expand Up @@ -128,12 +119,4 @@ export default class CatalogHelper {
const attrs = get<CatalogHelper, IAttrs>(this, ['dateDataSets', dataSetName, 'attributes']);
return getDisplayFormFromAttr(attrs, attributeName, displayFormName, 'tags');
}

private getMeasure(name: string) {
return get<CatalogHelper, string>(this, ['measures', name, 'identifier']);
}

private getMeasureTags(name: string) {
return get<CatalogHelper, string>(this, ['measures', name, 'tags']);
}
}
37 changes: 5 additions & 32 deletions src/helpers/tests/CatalogHelper.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,41 +38,14 @@ describe('CatalogHelper', () => {
}
};

const catalogWithMetricsJson = {
metrics: catalogJson.measures,
attributes: catalogJson.attributes,
visualizations: catalogJson.visualizations,
dateDataSets: catalogJson.dateDataSets
};

it('should return a measure', () => {
const catalogWithMeasures = new CatalogHelper(catalogJson);

expect(catalogWithMeasures.metric('Revenue')).toBe('123');
expect(catalogWithMeasures.metric('non-existent')).toBeUndefined();

expect(catalogWithMeasures.metricTags('Revenue')).toBe('abc');
expect(catalogWithMeasures.metricTags('non-existent')).toBeUndefined();

expect(catalogWithMeasures.measure('Revenue')).toBe('123');
expect(catalogWithMeasures.measure('non-existent')).toBeUndefined();

expect(catalogWithMeasures.measureTags('Revenue')).toBe('abc');
expect(catalogWithMeasures.measureTags('non-existent')).toBeUndefined();

const catalogWithMetrics = new CatalogHelper(catalogWithMetricsJson);

expect(catalogWithMetrics.metric('Revenue')).toBe('123');
expect(catalogWithMetrics.metric('non-existent')).toBeUndefined();

expect(catalogWithMetrics.metricTags('Revenue')).toBe('abc');
expect(catalogWithMetrics.metricTags('non-existent')).toBeUndefined();
const C = new CatalogHelper(catalogJson);

expect(catalogWithMetrics.measure('Revenue')).toBe('123');
expect(catalogWithMetrics.measure('non-existent')).toBeUndefined();
expect(C.measure('Revenue')).toBe('123');
expect(C.measure('non-existent')).toBeUndefined();

expect(catalogWithMetrics.measureTags('Revenue')).toBe('abc');
expect(catalogWithMetrics.measureTags('non-existent')).toBeUndefined();
expect(C.measureTags('Revenue')).toBe('abc');
expect(C.measureTags('non-existent')).toBeUndefined();
});

it('should return a visualization', () => {
Expand Down

0 comments on commit 68796d8

Please sign in to comment.