Merge pull request #1173 from theseyi/ret-over-test

additional retention override tests
This commit is contained in:
Seyi Adebajo 2018-05-21 11:12:13 -07:00 committed by GitHub
commit b7ace4a87c
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
13 changed files with 161 additions and 77 deletions

View File

@ -1,6 +1,7 @@
import { getJSON } from 'wherehows-web/utils/api/fetcher';
import { datasetUrlByUrn } from 'wherehows-web/utils/api/datasets/shared';
import { IDatasetView } from 'wherehows-web/typings/api/datasets/dataset';
import { encodeUrn } from 'wherehows-web/utils/validators/urn';
/**
* Constructs the url for a datasets upstreams
@ -15,6 +16,6 @@ const datasetUpstreamUrlByUrn = (urn: string): string => `${datasetUrlByUrn(urn)
* @return {Promise<Array<IDatasetView>>}
*/
const readUpstreamDatasetsByUrn = (urn: string): Promise<Array<IDatasetView>> =>
getJSON<Array<IDatasetView>>({ url: datasetUpstreamUrlByUrn(urn) });
getJSON<Array<IDatasetView>>({ url: datasetUpstreamUrlByUrn(encodeUrn(urn)) });
export { readUpstreamDatasetsByUrn };

View File

@ -30,7 +30,7 @@ const readDatasetRetentionByUrn = async (urn: string): Promise<IGetDatasetRetent
/**
* Persists the dataset retention policy remotely
* @param {string} urn the urn of the dataset to save
* @param {IDatasetRetention} retention the dataset retention policy to updae
* @param {IDatasetRetention} retention the dataset retention policy to update
* @return {Promise<IDatasetRetention>}
*/
const saveDatasetRetentionByUrn = (urn: string, retention: IDatasetRetention): Promise<IDatasetRetention> =>

View File

@ -22,6 +22,8 @@ import { getOwnerTypes } from 'wherehows-web/mirage/helpers/owner-types';
import { getConfig } from 'wherehows-web/mirage/helpers/config';
import { getAuth } from 'wherehows-web/mirage/helpers/authenticate';
import { aclAuth } from 'wherehows-web/mirage/helpers/aclauth';
import { getDatasetUpstreams } from 'wherehows-web/mirage/helpers/dataset-upstreams';
import { getDatasetRetention } from 'wherehows-web/mirage/helpers/dataset-retentions';
export default function(this: IMirageServer) {
this.get('/config', getConfig);
@ -46,6 +48,12 @@ export default function(this: IMirageServer) {
this.get('/list/platforms', getDatasetPlatforms);
this.get('/datasets/:dataset_id/upstreams', getDatasetUpstreams);
this.get('/datasets/:dataset_id/retention', getDatasetRetention);
this.get('/datasets/:dataset_id/compliance', getDatasetCompliance);
this.namespace = '/api/v1';
this.get('/datasets/:dataset_id', getDataset);

View File

@ -1,4 +1,6 @@
import { Factory, faker } from 'ember-cli-mirage';
import { DatasetPlatform } from 'wherehows-web/constants';
import { hdfsUrn, nonHdfsUrn } from 'wherehows-web/mirage/fixtures/urn';
export default Factory.extend({
createdTime: faker.date.past(2),
@ -9,9 +11,14 @@ export default Factory.extend({
modifiedTime: faker.date.recent(),
nativeName: 'abook.default-public-container',
nativeType: null,
platform: 'ambry',
platform: faker.list.random(...Object.values(DatasetPlatform)),
properties: '{}',
removed: faker.random.boolean(),
tags: null,
uri: 'ambry:///abook.default-public-container'
uri() {
const { platform } = this;
return platform === DatasetPlatform.HDFS
? hdfsUrn
: nonHdfsUrn.replace(/li:dataPlatform:db/, `li:dataPlatform:${platform}`);
}
});

View File

@ -1,3 +1,10 @@
import { Factory } from 'ember-cli-mirage';
import { Factory, faker } from 'ember-cli-mirage';
import { DatasetPlatform, PurgePolicy } from 'wherehows-web/constants';
export default Factory.extend({});
export default Factory.extend({
name: faker.list.random(...Object.values(DatasetPlatform)),
type: faker.lorem.words(1),
supportedPurgePolicies: Object.values(PurgePolicy)
});

View File

@ -0,0 +1,20 @@
import { Factory, faker } from 'ember-cli-mirage';
import { PurgePolicy } from 'wherehows-web/constants';
import { hdfsUrn, nonHdfsUrn } from 'wherehows-web/mirage/fixtures/urn';
export default Factory.extend({
datasetId: null,
datasetUrn: faker.list.random(hdfsUrn, nonHdfsUrn),
purgeType: faker.list.random(...Object.values(PurgePolicy)),
purgeNote() {
const { purgeType } = this;
return purgeType === PurgePolicy.PurgeExempt ? faker.lorem.words(5) : '';
},
modifiedBy: faker.internet.userName(),
modifiedTime: faker.date.past()
});

View File

@ -0,0 +1,3 @@
import { Factory } from 'ember-cli-mirage';
export default Factory.extend({});

View File

@ -1,10 +1,8 @@
import { IFunctionRouteHandler } from 'wherehows-web/typings/ember-cli-mirage';
import { ApiStatus } from 'wherehows-web/utils/api/shared';
const getDatasetPlatforms = function(this: IFunctionRouteHandler) {
const getDatasetPlatforms = function(this: IFunctionRouteHandler, { platforms }: { platforms: any }) {
return {
platforms: [],
status: ApiStatus.OK
platforms: this.serialize(platforms.all())
};
};

View File

@ -0,0 +1,9 @@
import { IFunctionRouteHandler } from 'wherehows-web/typings/ember-cli-mirage';
const getDatasetRetention = function(this: IFunctionRouteHandler, { retentions }: { retentions: any }) {
return {
retentionPolicy: this.serialize(retentions.first())
};
};
export { getDatasetRetention };

View File

@ -0,0 +1,3 @@
const getDatasetUpstreams = ({ datasetViews }: { datasetViews: any }) => datasetViews.all();
export { getDatasetUpstreams };

View File

@ -0,0 +1,3 @@
import { Model } from 'ember-cli-mirage';
export default Model;

View File

@ -0,0 +1,3 @@
import { Model } from 'ember-cli-mirage';
export default Model;

View File

@ -1,9 +1,13 @@
import { moduleForComponent, test } from 'ember-qunit';
import hbs from 'htmlbars-inline-precompile';
import { hdfsUrn } from 'wherehows-web/mirage/fixtures/urn';
import sinon from 'sinon';
import { waitUntil, find } from 'ember-native-dom-helpers';
import { startMirage } from 'wherehows-web/initializers/ember-cli-mirage';
import { waitUntil, find, findAll, click } from 'ember-native-dom-helpers';
import { DatasetPlatform, PurgePolicy } from 'wherehows-web/constants';
import { hdfsUrn } from 'wherehows-web/mirage/fixtures/urn';
const upstreamElement = '.upstream-dataset';
const downstreamPolicyEditButton = '#downstream-purge-edit';
const purgePolicyClass = '.purge-policy-list__item';
moduleForComponent(
'datasets/containers/upstream-dataset',
@ -12,83 +16,101 @@ moduleForComponent(
integration: true,
beforeEach() {
this.server = sinon.createFakeServer();
this.server.respondImmediately = true;
this.server = startMirage();
},
afterEach() {
this.server.restore();
this.server.shutdown();
}
}
);
test('it renders', async function(assert) {
assert.expect(1);
const upstreamElement = '.upstream-dataset';
const { server } = this;
const { nativeName, platform, uri } = server.create('datasetView');
this.set('urn', hdfsUrn);
this.set('platform', DatasetPlatform.HDFS);
this.server.respondWith(/\/api\/v2\/datasets.*\/upstreams/, function(xhr) {
xhr.respond(
200,
{ 'Content-Type': 'application/json' },
JSON.stringify([
{
nativeName: 'A nativeName',
platform: DatasetPlatform.HDFS,
uri: hdfsUrn
}
])
);
});
this.server.respondWith(/\/api\/v2\/datasets.*\/compliance/, function(xhr) {
xhr.respond(
200,
{ 'Content-Type': 'application/json' },
JSON.stringify({
datasetUrn: hdfsUrn
})
);
});
const retentionPolicy = {
datasetUrn: hdfsUrn,
purgeType: PurgePolicy.AutoPurge,
purgeNote: null
};
this.server.respondWith('GET', /\/api\/v2\/datasets.*\/retention/, [
200,
{ 'Content-Type': 'application/json' },
JSON.stringify({ retentionPolicy })
]);
this.server.respondWith('POST', /\/api\/v2\/datasets.*\/retention/, [
200,
{ 'Content-Type': 'application/json' },
JSON.stringify({ retentionPolicy })
]);
this.server.respondWith(/\/api\/v2\/list.*\/platforms/, function(xhr) {
xhr.respond(
200,
{ 'Content-Type': 'application/json' },
JSON.stringify({
platforms: [
{
name: DatasetPlatform.HDFS,
supportedPurgePolicies: [PurgePolicy.AutoLimitedRetention, PurgePolicy.AutoPurge]
}
]
})
);
});
this.set('urn', uri);
this.set('platform', platform);
this.render(hbs`{{datasets/containers/upstream-dataset urn=urn platform=platform}}`);
await waitUntil(() => find(upstreamElement));
assert.equal(find(upstreamElement).textContent.trim(), 'A nativeName');
assert.equal(find(upstreamElement).textContent.trim(), nativeName, 'renders the nativeName for the upstream element');
});
test('upstreams are rendered', async function(assert) {
assert.expect(1);
const { server } = this;
const upstreamsCount = 4;
const [{ uri, platform }] = server.createList('datasetView', upstreamsCount);
this.set('urn', uri);
this.set('platform', platform);
this.render(hbs`{{datasets/containers/upstream-dataset urn=urn platform=platform}}`);
await waitUntil(() => find(upstreamElement));
assert.equal(
findAll(upstreamElement).length,
upstreamsCount,
`renders ${upstreamsCount} elements for ${upstreamsCount} upstream datasets`
);
});
test('Compliance Purge Policy', async function(assert) {
assert.expect(3);
const downstreamClass = '.downstream-purge-policy';
const defaultMissingText = 'This dataset does not have a current compliance purge policy';
const { server } = this;
const { platform, uri } = server.create('datasetView');
this.set('urn', uri);
this.set('platform', platform);
this.render(hbs`{{datasets/containers/upstream-dataset urn=urn platform=platform}}`);
await waitUntil(() => find(downstreamClass));
assert.equal(
find(downstreamClass).textContent.trim(),
defaultMissingText,
'Shows the missing text string when there is no purge policy set'
);
assert.ok(find(downstreamPolicyEditButton), 'policy is editable');
server.create('platform');
server.create('retention');
this.render(hbs`{{datasets/containers/upstream-dataset urn=urn platform=platform}}`);
await waitUntil(() => find(purgePolicyClass) && find(purgePolicyClass).textContent.trim() !== defaultMissingText);
assert.ok(find.bind(find, purgePolicyClass), 'purge policy radio is rendered');
});
test('Edit Compliance Purge Policy', async function(assert) {
assert.expect(2);
const { server } = this;
const { platform, uri } = server.create('datasetView');
const { supportedPurgePolicies } = server.create('platform');
server.create('retention');
this.set('urn', uri);
this.set('platform', platform);
this.render(hbs`{{datasets/containers/upstream-dataset urn=urn platform=platform}}`);
await waitUntil(find.bind(find, downstreamPolicyEditButton));
click(downstreamPolicyEditButton);
assert.equal(findAll(purgePolicyClass).length, supportedPurgePolicies.length, 'renders all purge options on edit');
assert.equal(
find('.downstream-purge-policy__edit button').textContent.trim(),
'Save',
'clicking edit changes to edit mode'
);
});