mirror of
https://github.com/datahub-project/datahub.git
synced 2025-11-02 11:49:23 +00:00
Code cleanup. Modify tests and mirage handling
This commit is contained in:
parent
db227ac0fd
commit
dca71a796f
@ -10,16 +10,7 @@ import { IHealthScoreResponse, IDatasetHealth } from 'wherehows-web/typings/api/
|
|||||||
const datasetHealthUrlByUrn = (urn: string): string => `${datasetUrlByUrn(urn)}/health`;
|
const datasetHealthUrlByUrn = (urn: string): string => `${datasetUrlByUrn(urn)}/health`;
|
||||||
|
|
||||||
export const readDatasetHealthByUrn = async (urn: string): Promise<IDatasetHealth> => {
|
export const readDatasetHealthByUrn = async (urn: string): Promise<IDatasetHealth> => {
|
||||||
let health: IDatasetHealth;
|
const { health } = await getJSON<IHealthScoreResponse>({ url: datasetHealthUrlByUrn(urn) });
|
||||||
|
|
||||||
try {
|
return health || { score: 0, validations: [] };
|
||||||
({ health } = await getJSON<IHealthScoreResponse>({ url: datasetHealthUrlByUrn(urn) }));
|
|
||||||
} catch {
|
|
||||||
return {
|
|
||||||
score: 0,
|
|
||||||
validations: []
|
|
||||||
};
|
|
||||||
}
|
|
||||||
|
|
||||||
return health;
|
|
||||||
};
|
};
|
||||||
|
|||||||
@ -40,11 +40,5 @@ export default Factory.extend({
|
|||||||
schema(id: number) {
|
schema(id: number) {
|
||||||
return id === 0 ? testSchemaA : 'abcd';
|
return id === 0 ? testSchemaA : 'abcd';
|
||||||
}
|
}
|
||||||
}),
|
|
||||||
|
|
||||||
withHealth: trait({
|
|
||||||
afterCreate(dataset: any, server: any) {
|
|
||||||
server.create('health', 1, { dataset });
|
|
||||||
}
|
|
||||||
})
|
})
|
||||||
});
|
});
|
||||||
|
|||||||
@ -27,10 +27,6 @@ export default Factory.extend({
|
|||||||
return validations;
|
return validations;
|
||||||
},
|
},
|
||||||
|
|
||||||
refDatasetUrn() {
|
|
||||||
return this.dataset ? this.dataset.urn : 'fakeUrn';
|
|
||||||
},
|
|
||||||
|
|
||||||
forTesting: trait({
|
forTesting: trait({
|
||||||
score: 83,
|
score: 83,
|
||||||
validations() {
|
validations() {
|
||||||
|
|||||||
@ -1,9 +1,7 @@
|
|||||||
import { IFunctionRouteHandler } from 'wherehows-web/typings/ember-cli-mirage';
|
import { IFunctionRouteHandler } from 'wherehows-web/typings/ember-cli-mirage';
|
||||||
|
|
||||||
export const getDatasetHealth = function(this: IFunctionRouteHandler, { health }: any, request: any) {
|
export const getDatasetHealth = function(this: IFunctionRouteHandler, { db: healths }: any) {
|
||||||
const { dataset_id } = request.params;
|
|
||||||
|
|
||||||
return {
|
return {
|
||||||
health: health.filter((score: any) => score.refDatasetUrn === dataset_id)[0] || null
|
health: this.serialize(healths[0])
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
|
|||||||
@ -13,7 +13,7 @@ export default function(server: IMirageServer) {
|
|||||||
server.loadFixtures(...fixtures);
|
server.loadFixtures(...fixtures);
|
||||||
server.create('config');
|
server.create('config');
|
||||||
server.createList('owner', 6);
|
server.createList('owner', 6);
|
||||||
server.createList('dataset', 10, 'withHealth');
|
server.createList('dataset', 10);
|
||||||
server.createList('datasetView', 2);
|
server.createList('datasetView', 2);
|
||||||
server.createList('column', 2);
|
server.createList('column', 2);
|
||||||
server.createList('comment', 2);
|
server.createList('comment', 2);
|
||||||
@ -27,4 +27,5 @@ export default function(server: IMirageServer) {
|
|||||||
server.createList('suggestion', 2);
|
server.createList('suggestion', 2);
|
||||||
server.createList('platform', 2);
|
server.createList('platform', 2);
|
||||||
server.createList('version', 2);
|
server.createList('version', 2);
|
||||||
|
server.createList('health', 1);
|
||||||
}
|
}
|
||||||
|
|||||||
@ -1,20 +1,17 @@
|
|||||||
import { moduleForComponent, test } from 'ember-qunit';
|
import { module, test } from 'qunit';
|
||||||
import hbs from 'htmlbars-inline-precompile';
|
import { setupRenderingTest } from 'ember-qunit';
|
||||||
import { waitUntil, find } from 'ember-native-dom-helpers';
|
|
||||||
import { urn } from 'wherehows-web/mirage/fixtures/urn';
|
import { urn } from 'wherehows-web/mirage/fixtures/urn';
|
||||||
import sinon from 'sinon';
|
import { render, find } from '@ember/test-helpers';
|
||||||
|
import hbs from 'htmlbars-inline-precompile';
|
||||||
|
|
||||||
moduleForComponent(
|
module('Integration | Component | datasets/containers/dataset-health', function(hooks) {
|
||||||
'datasets/containers/dataset-health',
|
setupRenderingTest(hooks);
|
||||||
'Integration | Component | datasets/containers/dataset-health',
|
|
||||||
{
|
|
||||||
integration: true
|
|
||||||
}
|
|
||||||
);
|
|
||||||
|
|
||||||
test('it renders', async function(assert) {
|
test('it renders', async function(assert) {
|
||||||
this.set('urn', urn);
|
this.set('urn', urn);
|
||||||
this.render(hbs`{{datasets/containers/dataset-health urn=urn}}`);
|
await render(hbs`{{datasets/containers/dataset-health urn=urn}}`);
|
||||||
|
|
||||||
assert.ok(find('.dataset-health__score-table'), 'renders the health table component');
|
assert.ok(this.element, 'Renders without errors');
|
||||||
|
assert.ok(find('.dataset-health__score-table'), 'renders the health table component');
|
||||||
|
});
|
||||||
});
|
});
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user