2019-03-14 02:17:12 +00:00
|
|
|
import { module, test } from 'qunit';
|
|
|
|
import { setupTest } from 'ember-qunit';
|
2017-09-19 14:47:10 +00:00
|
|
|
import JobModel from 'nomad-ui/models/job';
|
|
|
|
|
2021-12-28 14:45:20 +00:00
|
|
|
module('Unit | Serializer | Job', function (hooks) {
|
2019-03-14 02:17:12 +00:00
|
|
|
setupTest(hooks);
|
2021-12-28 14:45:20 +00:00
|
|
|
hooks.beforeEach(function () {
|
2019-03-14 02:17:12 +00:00
|
|
|
this.store = this.owner.lookup('service:store');
|
|
|
|
this.subject = () => this.store.serializerFor('job');
|
|
|
|
});
|
2017-09-19 14:47:10 +00:00
|
|
|
|
2021-12-28 14:45:20 +00:00
|
|
|
test('`default` is used as the namespace in the job ID when there is no namespace in the payload', async function (assert) {
|
2019-03-14 02:17:12 +00:00
|
|
|
const original = {
|
|
|
|
ID: 'example',
|
|
|
|
Name: 'example',
|
|
|
|
};
|
2017-10-23 17:22:58 +00:00
|
|
|
|
2019-03-14 02:17:12 +00:00
|
|
|
const { data } = this.subject().normalize(JobModel, original);
|
|
|
|
assert.equal(data.id, JSON.stringify([data.attributes.name, 'default']));
|
|
|
|
});
|
2017-10-23 17:22:58 +00:00
|
|
|
|
2021-12-28 14:45:20 +00:00
|
|
|
test('The ID of the record is a composite of both the name and the namespace', async function (assert) {
|
2019-03-14 02:17:12 +00:00
|
|
|
const original = {
|
|
|
|
ID: 'example',
|
|
|
|
Name: 'example',
|
|
|
|
Namespace: 'special-namespace',
|
|
|
|
};
|
2017-10-23 17:22:58 +00:00
|
|
|
|
2019-03-14 02:17:12 +00:00
|
|
|
const { data } = this.subject().normalize(JobModel, original);
|
|
|
|
assert.equal(
|
|
|
|
data.id,
|
2021-12-28 16:08:12 +00:00
|
|
|
JSON.stringify([
|
|
|
|
data.attributes.name,
|
|
|
|
data.relationships.namespace.data.id,
|
|
|
|
])
|
2019-03-14 02:17:12 +00:00
|
|
|
);
|
|
|
|
});
|
2017-10-23 17:22:58 +00:00
|
|
|
});
|