Files
threshold-ui/addons/api/tests/unit/serializers/host-set-test.js
T

109 lines
3.1 KiB
JavaScript
Raw Normal View History

2020-08-19 18:38:18 -04:00
import { module, test } from 'qunit';
import { setupTest } from 'ember-qunit';
2020-09-16 14:29:02 -04:00
module('Unit | Serializer | host set', function (hooks) {
2020-08-19 18:38:18 -04:00
setupTest(hooks);
test('it serializes host sets normally, without host_ids', function (assert) {
assert.expect(1);
const store = this.owner.lookup('service:store');
const serializer = store.serializerFor('host-set');
const record = store.createRecord('host-set', {
name: 'Host Set 1',
description: 'Description',
2020-09-10 17:59:31 -04:00
host_catalog_id: '123',
2020-09-16 14:29:02 -04:00
version: 1,
2020-08-19 18:38:18 -04:00
});
const snapshot = record._createSnapshot();
snapshot.adapterOptions = {};
const serializedRecord = serializer.serialize(snapshot);
assert.deepEqual(serializedRecord, {
name: 'Host Set 1',
description: 'Description',
2020-09-10 17:59:31 -04:00
host_catalog_id: '123',
2020-09-16 14:29:02 -04:00
version: 1,
2020-08-19 18:38:18 -04:00
});
});
test('it serializes only host_ids when `adapterOptions.hostIDs` is true', function (assert) {
2020-08-19 18:38:18 -04:00
assert.expect(1);
const store = this.owner.lookup('service:store');
const serializer = store.serializerFor('host-set');
const record = store.createRecord('host-set', {
name: 'Host Set 1',
description: 'Description',
2020-09-16 14:29:02 -04:00
host_ids: [{ value: '1' }, { value: '2' }, { value: '3' }],
version: 1,
2020-08-19 18:38:18 -04:00
});
const snapshot = record._createSnapshot();
snapshot.adapterOptions = {
2020-09-16 14:29:02 -04:00
hostIDs: ['4', '5'],
2020-08-19 18:38:18 -04:00
};
const serializedRecord = serializer.serialize(snapshot);
assert.deepEqual(serializedRecord, {
host_ids: ['4', '5'],
2020-09-16 14:29:02 -04:00
version: 1,
2020-08-19 18:38:18 -04:00
});
});
test('it normalizes records with array fields', function (assert) {
assert.expect(1);
const store = this.owner.lookup('service:store');
const serializer = store.serializerFor('host-set');
const hostSetModelClass = store.createRecord('host-set').constructor;
const payload = {
id: '1',
name: 'Host Set 1',
2020-09-16 14:29:02 -04:00
host_ids: ['1', '2', '3'],
2020-08-19 18:38:18 -04:00
};
const normalized = serializer.normalizeSingleResponse(
store,
hostSetModelClass,
payload
);
assert.deepEqual(normalized, {
included: [],
data: {
id: '1',
type: 'host-set',
attributes: {
2021-08-04 17:58:08 -04:00
authorized_actions: [],
2020-08-19 18:38:18 -04:00
name: 'Host Set 1',
2020-09-16 14:29:02 -04:00
host_ids: [{ value: '1' }, { value: '2' }, { value: '3' }],
2020-08-19 18:38:18 -04:00
},
relationships: {},
},
});
});
2020-09-12 11:20:38 -04:00
test('it normalizes missing host_ids to empty array', function (assert) {
assert.expect(1);
2020-09-12 11:20:38 -04:00
const store = this.owner.lookup('service:store');
const serializer = store.serializerFor('host-set');
const hostSet = store.createRecord('host-set').constructor;
const payload = {
id: '1',
name: 'Host Set 1',
2020-09-16 14:29:02 -04:00
scope: { id: 'o_123' },
2020-09-12 11:20:38 -04:00
};
const normalized = serializer.normalizeSingleResponse(
store,
hostSet,
payload
);
assert.deepEqual(normalized, {
included: [],
data: {
id: '1',
type: 'host-set',
attributes: {
2021-08-04 17:58:08 -04:00
authorized_actions: [],
2020-09-12 11:20:38 -04:00
name: 'Host Set 1',
scope: { scope_id: 'o_123' },
2020-09-16 14:29:02 -04:00
host_ids: [],
2020-09-12 11:20:38 -04:00
},
relationships: {},
},
});
});
2020-08-19 18:38:18 -04:00
});