Skip to content

Commit

Permalink
fix: ACNA-2078 - add api url e2e test (#155)
Browse files Browse the repository at this point in the history
* remove reachability check, add creation check only
  • Loading branch information
shazron authored Aug 22, 2023
1 parent 58b6d80 commit df47319
Show file tree
Hide file tree
Showing 3 changed files with 46 additions and 9 deletions.
39 changes: 35 additions & 4 deletions e2e/e2e.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ const { createHttpsProxy } = require('@adobe/aio-lib-test-proxy')

jest.unmock('openwhisk')
jest.unmock('archiver')
jest.setTimeout(40000)
jest.setTimeout(60000)

// load .env values in the e2e folder, if any
require('dotenv').config({ path: path.join(__dirname, '.env') })
Expand Down Expand Up @@ -113,6 +113,39 @@ describe('build, deploy, invoke and undeploy of actions', () => {
expect.objectContaining({ name: 'action', namespace: expect.stringContaining('/sample-app-1.0.0') })]))
await sdkClient.actions.invoke('sample-app-1.0.0/action')

// Verify apis are created in openwhisk
const basepath = 'base'
const relpath = 'path'
const { apis } = await sdkClient.routes.list({ basepath, relpath })

expect(apis.length).toEqual(1)
expect(apis[0].value.apidoc.basePath).toEqual(`/${basepath}`)
expect(apis[0].value.apidoc.info.title).toEqual('api1')
expect(apis[0].value.apidoc.paths[`/${relpath}`].get).toEqual(expect.any(Object))

// we can't test the reachability of the API paths below because it may take up
// to 5 mins for an API to be available:
// https://adobedocs.github.io/adobeio-runtime/guides/creating_rest_apis.html#how-long-does-it-take-to-createupdate-an-api

// const api = apis[0]
// const paths = api.value.apidoc.paths
// for (const key of Object.keys(paths)) {
// if (!key.startsWith('/')) {
// return
// }

// const { createFetch } = require('@adobe/aio-lib-core-networking')
// const path = paths[key]
// for (const verb of Object.keys(path)) {
// const fetch = createFetch()
// const url = `${api.value.gwApiUrl}${key}`
// console.log('testing API Url:', url)
// const response = await fetch(url, { method: verb })
// console.log('API Url response status:', response.status)
// expect(response.status).not.toEqual(404)
// }
// }

// Undeploy
await sdk.undeployActions(config)
actions = await sdkClient.actions.list({ limit: 1 })
Expand Down Expand Up @@ -239,7 +272,6 @@ describe('print logs', () => {
const logs = []
const storeLogs = (str) => { logs.push(str) }
// Runtime waits for about 60 secs to return a 503 when it cannot serve the request.
jest.setTimeout(100000)
try {
const retResult = await sdk.printActionLogs(config, storeLogs, 1, [], false, false)
expect(typeof retResult).toEqual('object')
Expand All @@ -249,8 +281,7 @@ describe('print logs', () => {
expect(err.message).toEqual(expect.stringContaining('503')) // eslint-disable-line jest/no-conditional-expect
expect(err.message).toEqual(expect.stringContaining('Service Unavailable')) // eslint-disable-line jest/no-conditional-expect
}
jest.setTimeout(30000)
})
}, 100000)
})

test('delete non-existing trigger', async () => {
Expand Down
12 changes: 9 additions & 3 deletions e2e/jest.setup.js
Original file line number Diff line number Diff line change
Expand Up @@ -105,12 +105,12 @@ global.sampleAppConfig = {
action: {
function: 'actions/action.js',
web: 'yes',
runtime: 'nodejs:12'
runtime: 'nodejs:16'
},
'action-zip': {
function: 'actions/action-zip',
web: 'yes',
runtime: 'nodejs:12'
runtime: 'nodejs:16'
}
},
sequences: {
Expand All @@ -122,7 +122,13 @@ global.sampleAppConfig = {
},
apis: {
api1: {
base: { path: { action: { method: 'get' } } }
base: {
path: {
action: {
method: 'get'
}
}
}
}
},
dependencies: { dependency1: { location: '/adobeio/oauth' } }
Expand Down
4 changes: 2 additions & 2 deletions test/__fixtures__/sample-app/manifest.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,11 @@ packages:
action:
function: actions/action.js
web: yes
runtime: 'nodejs:12'
runtime: 'nodejs:16'
action-zip:
function: actions/action-zip
web: yes
runtime: 'nodejs:12'
runtime: 'nodejs:16'
sequences:
action-sequence:
actions: action, action-zip
Expand Down

0 comments on commit df47319

Please sign in to comment.