mirror of
https://github.com/datahub-project/datahub.git
synced 2025-11-01 11:19:05 +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`;
|
||||
|
||||
export const readDatasetHealthByUrn = async (urn: string): Promise<IDatasetHealth> => {
|
||||
let health: IDatasetHealth;
|
||||
const { health } = await getJSON<IHealthScoreResponse>({ url: datasetHealthUrlByUrn(urn) });
|
||||
|
||||
try {
|
||||
({ health } = await getJSON<IHealthScoreResponse>({ url: datasetHealthUrlByUrn(urn) }));
|
||||
} catch {
|
||||
return {
|
||||
score: 0,
|
||||
validations: []
|
||||
};
|
||||
}
|
||||
|
||||
return health;
|
||||
return health || { score: 0, validations: [] };
|
||||
};
|
||||
|
||||
@ -40,11 +40,5 @@ export default Factory.extend({
|
||||
schema(id: number) {
|
||||
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;
|
||||
},
|
||||
|
||||
refDatasetUrn() {
|
||||
return this.dataset ? this.dataset.urn : 'fakeUrn';
|
||||
},
|
||||
|
||||
forTesting: trait({
|
||||
score: 83,
|
||||
validations() {
|
||||
|
||||
@ -1,9 +1,7 @@
|
||||
import { IFunctionRouteHandler } from 'wherehows-web/typings/ember-cli-mirage';
|
||||
|
||||
export const getDatasetHealth = function(this: IFunctionRouteHandler, { health }: any, request: any) {
|
||||
const { dataset_id } = request.params;
|
||||
|
||||
export const getDatasetHealth = function(this: IFunctionRouteHandler, { db: healths }: any) {
|
||||
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.create('config');
|
||||
server.createList('owner', 6);
|
||||
server.createList('dataset', 10, 'withHealth');
|
||||
server.createList('dataset', 10);
|
||||
server.createList('datasetView', 2);
|
||||
server.createList('column', 2);
|
||||
server.createList('comment', 2);
|
||||
@ -27,4 +27,5 @@ export default function(server: IMirageServer) {
|
||||
server.createList('suggestion', 2);
|
||||
server.createList('platform', 2);
|
||||
server.createList('version', 2);
|
||||
server.createList('health', 1);
|
||||
}
|
||||
|
||||
@ -1,20 +1,17 @@
|
||||
import { moduleForComponent, test } from 'ember-qunit';
|
||||
import hbs from 'htmlbars-inline-precompile';
|
||||
import { waitUntil, find } from 'ember-native-dom-helpers';
|
||||
import { module, test } from 'qunit';
|
||||
import { setupRenderingTest } from 'ember-qunit';
|
||||
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(
|
||||
'datasets/containers/dataset-health',
|
||||
'Integration | Component | datasets/containers/dataset-health',
|
||||
{
|
||||
integration: true
|
||||
}
|
||||
);
|
||||
module('Integration | Component | datasets/containers/dataset-health', function(hooks) {
|
||||
setupRenderingTest(hooks);
|
||||
|
||||
test('it renders', async function(assert) {
|
||||
this.set('urn', urn);
|
||||
this.render(hbs`{{datasets/containers/dataset-health urn=urn}}`);
|
||||
test('it renders', async function(assert) {
|
||||
this.set('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