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

174 lines
5.0 KiB
JavaScript
Raw Normal View History

2022-01-20 08:32:13 -08:00
import { module, test } from 'qunit';
import { setupTest } from 'ember-qunit';
module('Unit | Serializer | host catalog', function (hooks) {
setupTest(hooks);
// Replace this with your real tests.
test('it exists', function (assert) {
2022-01-21 10:05:04 -08:00
const store = this.owner.lookup('service:store');
const serializer = store.serializerFor('host-catalog');
2022-01-20 08:32:13 -08:00
assert.ok(serializer);
});
test('it serializes records', function (assert) {
2022-01-21 10:05:04 -08:00
const store = this.owner.lookup('service:store');
const record = store.createRecord('host-catalog', {});
2022-01-20 08:32:13 -08:00
2022-01-21 10:05:04 -08:00
assert.ok(record.serialize());
2022-01-20 08:32:13 -08:00
});
test('it serializes a static host-catalog as expected', async function (assert) {
assert.expect(1);
const store = this.owner.lookup('service:store');
const record = store.createRecord('host-catalog', {
name: 'static',
description: 'this is a static host-catalog',
type: 'static',
});
const expectedResult = {
name: 'static',
description: 'this is a static host-catalog',
type: 'static',
};
2022-01-21 10:05:04 -08:00
assert.deepEqual(record.serialize(), expectedResult);
2022-01-20 08:32:13 -08:00
});
test('it serializes a new aws plugin as expected, ignoring azure fields', async function (assert) {
2022-01-20 08:32:13 -08:00
assert.expect(1);
const store = this.owner.lookup('service:store');
const record = store.createRecord('host-catalog', {
2022-01-20 16:47:46 -05:00
compositeType: 'aws',
name: 'AWS',
2022-01-20 08:32:13 -08:00
description: 'this is a Aws plugin host-catalog',
disable_credential_rotation: true,
2022-01-20 16:47:46 -05:00
// these are AWS fields and should be included
region: 'spain',
access_key_id: 'foobars',
secret_access_key: 'testing',
// these are Azure fields and should be excluded
2022-01-20 08:32:13 -08:00
tenant_id: 'a1b2c3',
client_id: 'a1b2c3',
subscription_id: 'a1b2c3',
2022-01-20 16:47:46 -05:00
secret_id: 'a1b2c3',
secret_value: 'a1b2c3',
2022-01-20 08:32:13 -08:00
});
const expectedResult = {
2022-01-20 16:47:46 -05:00
name: 'AWS',
2022-01-20 08:32:13 -08:00
description: 'this is a Aws plugin host-catalog',
type: 'plugin',
attributes: {
disable_credential_rotation: true,
2022-01-20 16:47:46 -05:00
region: 'spain',
},
secrets: {
2022-01-20 16:47:46 -05:00
access_key_id: 'foobars',
secret_access_key: 'testing',
2022-01-20 08:32:13 -08:00
},
};
2022-01-21 10:05:04 -08:00
assert.deepEqual(record.serialize(), expectedResult);
2022-01-20 08:32:13 -08:00
});
test('it serializes a new azure record as expected, ignoring aws fields', async function (assert) {
2022-01-20 08:32:13 -08:00
assert.expect(1);
const store = this.owner.lookup('service:store');
const record = store.createRecord('host-catalog', {
2022-01-20 16:47:46 -05:00
compositeType: 'azure',
2022-01-20 08:32:13 -08:00
name: 'Azure',
description: 'this is a Azure plugin host-catalog',
disable_credential_rotation: true,
region: 'spain',
2022-01-20 16:47:46 -05:00
access_key_id: 'foobars',
secret_access_key: 'testing',
// these are Azure fields and should be excluded
tenant_id: 'a1b2c3',
client_id: 'a1b2c3',
subscription_id: 'a1b2c3',
secret_id: 'a1b2c3',
secret_value: 'a1b2c3',
2022-01-20 08:32:13 -08:00
});
const expectedResult = {
name: 'Azure',
description: 'this is a Azure plugin host-catalog',
type: 'plugin',
attributes: {
disable_credential_rotation: true,
2022-01-20 16:47:46 -05:00
tenant_id: 'a1b2c3',
client_id: 'a1b2c3',
subscription_id: 'a1b2c3',
},
secrets: {
2022-01-20 16:47:46 -05:00
secret_id: 'a1b2c3',
secret_value: 'a1b2c3',
2022-01-20 08:32:13 -08:00
},
};
2022-01-21 10:05:04 -08:00
assert.deepEqual(record.serialize(), expectedResult);
2022-01-20 08:32:13 -08:00
});
2022-01-21 09:49:48 -08:00
test('it serializes an existing aws record correctly', function (assert) {
2022-01-21 09:49:48 -08:00
assert.expect(1);
const store = this.owner.lookup('service:store');
store.push({
data: {
id: '1',
type: 'host-catalog',
attributes: {
type: 'plugin',
name: 'aws',
description: 'test description',
plugin: {
name: 'aws',
},
region: 'andorra',
},
},
});
const record = store.peekRecord('host-catalog', '1');
const expectedResult = {
type: 'plugin',
name: 'aws',
description: 'test description',
attributes: {
disable_credential_rotation: false,
region: 'andorra',
},
2022-01-21 09:49:48 -08:00
};
2022-01-21 10:05:04 -08:00
assert.deepEqual(record.serialize(), expectedResult);
2022-01-21 09:49:48 -08:00
});
test('it serializes an existing azure record correctly', function (assert) {
2022-01-21 09:49:48 -08:00
assert.expect(1);
const store = this.owner.lookup('service:store');
store.push({
data: {
id: '2',
type: 'host-catalog',
attributes: {
type: 'plugin',
name: 'azure',
description: 'test description',
plugin: {
name: 'azure',
},
tenant_id: 'a1b2c3',
client_id: 'foobars12',
subscription_id: 'barsfoo21',
},
},
});
const record = store.peekRecord('host-catalog', '2');
const expectedResult = {
type: 'plugin',
name: 'azure',
description: 'test description',
attributes: {
disable_credential_rotation: false,
tenant_id: 'a1b2c3',
client_id: 'foobars12',
subscription_id: 'barsfoo21',
},
2022-01-21 09:49:48 -08:00
};
2022-01-21 10:05:04 -08:00
assert.deepEqual(record.serialize(), expectedResult);
2022-01-21 09:49:48 -08:00
});
2022-01-20 08:32:13 -08:00
});