Skip to content

Commit

Permalink
improve testing
Browse files Browse the repository at this point in the history
  • Loading branch information
justinedelson committed Jul 8, 2020
1 parent 856f90b commit 5f240f5
Show file tree
Hide file tree
Showing 5 changed files with 98 additions and 17 deletions.
56 changes: 56 additions & 0 deletions test/base-command.test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
/*
Copyright 2020 Adobe. All rights reserved.
This file is licensed to you under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License. You may obtain a copy
of the License at http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software distributed under
the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS
OF ANY KIND, either express or implied. See the License for the specific language
governing permissions and limitations under the License.
*/


const { resetCurrentOrgId, setCurrentOrgId, context } = require('@adobe/aio-lib-ims')
const Config = require('@adobe/aio-lib-core-config')
const BaseCommand = require('../src/base-command')

beforeEach(() => {
resetCurrentOrgId()
})

test('base-command - missing config', async () => {
expect.assertions(2)

let runResult = new BaseCommand().withClient(undefined, () => undefined)
await expect(runResult instanceof Promise).toBeTruthy()
await expect(runResult).rejects.toEqual(new Error('Unable to find IMS context aio-cli-plugin-cloudmanager'))
})

test('base-command - no passphrase', async () => {
setCurrentOrgId('not-found')

expect.assertions(2)

let runResult = new BaseCommand().withClient(undefined, () => true)
await expect(runResult instanceof Promise).toBeTruthy()
await expect(runResult).resolves.toBeTruthy()
})

test('base-command - passphrase', async () => {
setCurrentOrgId('not-found')

expect.assertions(7)

let runResult = new BaseCommand().withClient('something', () => true)
await expect(runResult instanceof Promise).toBeTruthy()
await expect(runResult).resolves.toBeTruthy()
await expect(context.set.mock.calls.length).toEqual(1)
await expect(context.set.mock.calls[0][1].passphrase).toEqual('something')
await expect(context.set.mock.calls[0][2]).toBeTruthy()

const contextName = context.set.mock.calls[0][0]
await expect(Config.delete.mock.calls.length).toEqual(1)
await expect(Config.delete.mock.calls[0][0]).toEqual(`ims.contexts.${contextName}`)

})
33 changes: 27 additions & 6 deletions test/cloudmanager-helpers.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,8 @@ OF ANY KIND, either express or implied. See the License for the specific languag
governing permissions and limitations under the License.
*/

const {isWithinFiveMinutesOfUTCMidnight} = require('../src/cloudmanager-helpers')

beforeEach(() => {
jest.clearAllMocks()
jest.resetAllMocks()
})
const { setStore } = require('@adobe/aio-lib-core-config')
const { isWithinFiveMinutesOfUTCMidnight, getBaseUrl } = require('../src/cloudmanager-helpers')

test('isWithinFiveMinutesOfUTCMidnight', async () => {
const utcDate1 = new Date(Date.UTC(2019, 9, 12, 23, 55, 14));
Expand All @@ -27,3 +23,28 @@ test('isWithinFiveMinutesOfUTCMidnight', async () => {
const utcDate4 = new Date(Date.UTC(2019, 9, 12, 0, 6, 0));
expect(isWithinFiveMinutesOfUTCMidnight(utcDate4)).toEqual(false)
})

test('getting base url - bad value', async () => {
setStore({
'cloudmanager': '5'
})
const result = getBaseUrl()
await expect(result instanceof Promise).toBeTruthy()
await expect(result).resolves.toEqual('https://cloudmanager.adobe.io')
})

test('getting base url - default', async () => {
const result = getBaseUrl()
await expect(result instanceof Promise).toBeTruthy()
await expect(result).resolves.toEqual('https://cloudmanager.adobe.io')
})

test('getting base url - custom', async () => {
setStore({
'cloudmanager': JSON.stringify({'base_url' : 'http://www.test.com'})
})

const result = getBaseUrl()
await expect(result instanceof Promise).toBeTruthy()
await expect(result).resolves.toEqual('http://www.test.com')
})
6 changes: 3 additions & 3 deletions test/commands/delete-pipeline.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ test('delete-pipeline - missing config', async () => {
})

test('delete-pipeline - delete pipeline returns 400', async () => {
setCurrentOrgId('good')
setCurrentOrgId('good')

expect.assertions(3)

Expand All @@ -47,7 +47,7 @@ setCurrentOrgId('good')
})

test('delete-pipeline - bad pipeline', async () => {
setCurrentOrgId('good')
setCurrentOrgId('good')

expect.assertions(3)

Expand All @@ -58,7 +58,7 @@ setCurrentOrgId('good')
})

test('delete-pipeline - success', async () => {
setCurrentOrgId('good')
setCurrentOrgId('good')

expect.assertions(3)

Expand Down
8 changes: 0 additions & 8 deletions test/commands/list-programs.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,14 +17,6 @@ beforeEach(() => {
resetCurrentOrgId()
})

test('list-programs - missing config', async () => {
expect.assertions(2)

let runResult = ListProgramsCommand.run([])
await expect(runResult instanceof Promise).toBeTruthy()
await expect(runResult).rejects.toEqual(new Error('Unable to find IMS context aio-cli-plugin-cloudmanager'))
})

test('list-programs - failure', async () => {
setCurrentOrgId('not-found')
expect.assertions(2)
Expand Down
12 changes: 12 additions & 0 deletions test/hooks/migrate-jwt-context-hook.test.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,15 @@
/*
Copyright 2020 Adobe. All rights reserved.
This file is licensed to you under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License. You may obtain a copy
of the License at http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software distributed under
the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS
OF ANY KIND, either express or implied. See the License for the specific language
governing permissions and limitations under the License.
*/

const { setStore, set } = require('@adobe/aio-lib-core-config')
const migrate = require('../../src/hooks/migrate-jwt-context-hook')

Expand Down

0 comments on commit 5f240f5

Please sign in to comment.