From ffb00c708f19f3a9c78873c89289e3924646a7e2 Mon Sep 17 00:00:00 2001 From: Carlos Alcaide Corvo Date: Mon, 24 Jan 2022 10:01:17 -0800 Subject: [PATCH] Refactor mirage factory. Rephrase test description. Refactor some tests to not test secret fields --- addons/api/mirage/factories/host-catalog.js | 34 +++++++++---------- .../generated/factories/host-catalog.js | 1 - .../unit/serializers/host-catalog-test.js | 21 +++--------- 3 files changed, 21 insertions(+), 35 deletions(-) diff --git a/addons/api/mirage/factories/host-catalog.js b/addons/api/mirage/factories/host-catalog.js index f7c82a20d..3179f2c99 100644 --- a/addons/api/mirage/factories/host-catalog.js +++ b/addons/api/mirage/factories/host-catalog.js @@ -18,23 +18,23 @@ export default factory.extend({ }; }, attributes() { - if (this.plugin) { - switch (this.plugin.name) { - case 'aws': - return { - tenant_id: datatype.hexaDecimal(6), - client_id: datatype.hexaDecimal(6), - subscription_id: datatype.hexaDecimal(8), - secret_id: datatype.hexaDecimal(6), - secret_value: datatype.string(12), - }; - case 'azure': - return { - region: address.state(), - access_key_id: datatype.hexaDecimal(8), - secret_access_key: datatype.string(12), - }; - } + switch (this.plugin?.name) { + case 'aws': + return { + disable_credential_rotation: datatype.boolean(), + tenant_id: datatype.hexaDecimal(6), + client_id: datatype.hexaDecimal(6), + subscription_id: datatype.hexaDecimal(8), + secret_id: datatype.hexaDecimal(6), + secret_value: datatype.string(12), + }; + case 'azure': + return { + disable_credential_rotation: datatype.boolean(), + region: address.state(), + access_key_id: datatype.hexaDecimal(8), + secret_access_key: datatype.string(12), + }; } }, withChildren: trait({ diff --git a/addons/api/mirage/generated/factories/host-catalog.js b/addons/api/mirage/generated/factories/host-catalog.js index 20601e2f3..fa8135226 100644 --- a/addons/api/mirage/generated/factories/host-catalog.js +++ b/addons/api/mirage/generated/factories/host-catalog.js @@ -20,5 +20,4 @@ export default Factory.extend({ }; } }, - disable_credential_rotation: () => datatype.boolean(), }); diff --git a/addons/api/tests/unit/serializers/host-catalog-test.js b/addons/api/tests/unit/serializers/host-catalog-test.js index 018f1a1d8..d82869348 100644 --- a/addons/api/tests/unit/serializers/host-catalog-test.js +++ b/addons/api/tests/unit/serializers/host-catalog-test.js @@ -35,7 +35,7 @@ module('Unit | Serializer | host catalog', function (hooks) { assert.deepEqual(record.serialize(), expectedResult); }); - test('it serializes an AWS plugin as expected, ignoring Azure fields', async function (assert) { + test('it serializes a new aws plugin as expected, ignoring azure fields', async function (assert) { assert.expect(1); const store = this.owner.lookup('service:store'); const record = store.createRecord('host-catalog', { @@ -70,7 +70,7 @@ module('Unit | Serializer | host catalog', function (hooks) { assert.deepEqual(record.serialize(), expectedResult); }); - test('it serializes an Azure plugin as expected, ignoring AWS fields', async function (assert) { + test('it serializes a new azure record as expected, ignoring aws fields', async function (assert) { assert.expect(1); const store = this.owner.lookup('service:store'); const record = store.createRecord('host-catalog', { @@ -78,7 +78,6 @@ module('Unit | Serializer | host catalog', function (hooks) { name: 'Azure', description: 'this is a Azure plugin host-catalog', disable_credential_rotation: true, - // these are AWS fields and should be included region: 'spain', access_key_id: 'foobars', secret_access_key: 'testing', @@ -107,7 +106,7 @@ module('Unit | Serializer | host catalog', function (hooks) { assert.deepEqual(record.serialize(), expectedResult); }); - test('it serializes aws correctly on update', function (assert) { + test('it serializes an existing aws record correctly', function (assert) { assert.expect(1); const store = this.owner.lookup('service:store'); store.push({ @@ -122,8 +121,6 @@ module('Unit | Serializer | host catalog', function (hooks) { name: 'aws', }, region: 'andorra', - access_key_id: 'foobars', - secret_access_key: 'testing', }, }, }); @@ -136,15 +133,11 @@ module('Unit | Serializer | host catalog', function (hooks) { disable_credential_rotation: false, region: 'andorra', }, - secrets: { - access_key_id: 'foobars', - secret_access_key: 'testing', - }, }; assert.deepEqual(record.serialize(), expectedResult); }); - test('it serializes azure correctly on update', function (assert) { + test('it serializes an existing azure record correctly', function (assert) { assert.expect(1); const store = this.owner.lookup('service:store'); store.push({ @@ -161,8 +154,6 @@ module('Unit | Serializer | host catalog', function (hooks) { tenant_id: 'a1b2c3', client_id: 'foobars12', subscription_id: 'barsfoo21', - secret_id: 'secretBar12', - secret_value: 'secretValue21', }, }, }); @@ -177,10 +168,6 @@ module('Unit | Serializer | host catalog', function (hooks) { client_id: 'foobars12', subscription_id: 'barsfoo21', }, - secrets: { - secret_id: 'secretBar12', - secret_value: 'secretValue21', - }, }; assert.deepEqual(record.serialize(), expectedResult); });