From 549737405be4d85ecc56f0e3080d9708cda67b20 Mon Sep 17 00:00:00 2001 From: mabashian Date: Thu, 14 Sep 2017 09:14:27 -0400 Subject: [PATCH] Fixed multi credential service unit test failures Signed-off-by: mabashian --- .../multi-credential.service.js | 2 +- .../multi-credential.service-test.js | 78 ++++++++++++++++++- 2 files changed, 77 insertions(+), 3 deletions(-) diff --git a/awx/ui/client/src/templates/job_templates/multi-credential/multi-credential.service.js b/awx/ui/client/src/templates/job_templates/multi-credential/multi-credential.service.js index 806a8bb442..a22937fb61 100644 --- a/awx/ui/client/src/templates/job_templates/multi-credential/multi-credential.service.js +++ b/awx/ui/client/src/templates/job_templates/multi-credential/multi-credential.service.js @@ -138,7 +138,7 @@ export default ['Rest', 'ProcessErrors', '$q', 'GetBasePath', function(Rest, Pro name: cred.name, id: cred.id, postType: cred.postType, - readOnly: cred.readOnly, + readOnly: cred.readOnly ? true : false, kind: typeOpts .filter(type => { return parseInt(cred.credential_type) === type.value; diff --git a/awx/ui/tests/spec/multi-credential/multi-credential.service-test.js b/awx/ui/tests/spec/multi-credential/multi-credential.service-test.js index 9f47abd231..98eeb48070 100644 --- a/awx/ui/tests/spec/multi-credential/multi-credential.service-test.js +++ b/awx/ui/tests/spec/multi-credential/multi-credential.service-test.js @@ -1,4 +1,4 @@ -'use strict' +'use strict'; describe('MultiCredentialService', () => { let MultiCredentialService; @@ -79,7 +79,7 @@ describe('MultiCredentialService', () => { expect(equal).toBe(true); }); - it('should return array of selected credentials (populated)', () => { + it('should return array of selected credentials (populated, not read only)', () => { let creds = { machine: { credential_type: 1, @@ -120,18 +120,92 @@ describe('MultiCredentialService', () => { name: 'ssh', id: 3, postType: 'machine', + readOnly: false, kind: 'SSH:' }, { name: 'aws', id: 4, postType: 'extra', + readOnly: false, kind: 'Amazon Web Services:' }, { name: 'gce', id: 5, postType: 'extra', + readOnly: false, + kind: 'Google Compute Engine:' + } + ]; + + let actual = MultiCredentialService + .updateCredentialTags(creds, typeOpts); + + let equal = _.isEqual(expected.sort(), actual.sort()); + + expect(equal).toBe(true); + }); + + it('should return array of selected credentials (populated, read only)', () => { + let creds = { + machine: { + credential_type: 1, + id: 3, + name: 'ssh', + readOnly: true + }, + extra: [ + { + credential_type: 2, + id: 4, + name: 'aws', + readOnly: true + }, + { + credential_type: 3, + id: 5, + name: 'gce', + readOnly: true + } + ] + }; + + let typeOpts = [ + { + name: 'SSH', + value: 1 + }, + { + name: 'Amazon Web Services', + value: 2 + }, + { + name: 'Google Compute Engine', + value: 3 + } + ]; + + let expected = [ + { + name: 'ssh', + id: 3, + postType: 'machine', + readOnly: true, + kind: 'SSH:' + }, + { + name: 'aws', + id: 4, + postType: 'extra', + readOnly: true, + kind: 'Amazon Web Services:' + }, + { + name: 'gce', + id: 5, + postType: 'extra', + readOnly: true, kind: 'Google Compute Engine:' } ];