From df4731938f0fbb8ddb42e811455a70604e727257 Mon Sep 17 00:00:00 2001 From: Shazron Abdullah <36107+shazron@users.noreply.github.com> Date: Tue, 22 Aug 2023 20:44:42 +0800 Subject: [PATCH] fix: ACNA-2078 - add api url e2e test (#155) * remove reachability check, add creation check only --- e2e/e2e.js | 39 ++++++++++++++++++++--- e2e/jest.setup.js | 12 +++++-- test/__fixtures__/sample-app/manifest.yml | 4 +-- 3 files changed, 46 insertions(+), 9 deletions(-) diff --git a/e2e/e2e.js b/e2e/e2e.js index b5f2691..94e56c4 100644 --- a/e2e/e2e.js +++ b/e2e/e2e.js @@ -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') }) @@ -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 }) @@ -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') @@ -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 () => { diff --git a/e2e/jest.setup.js b/e2e/jest.setup.js index fabd968..d5a9039 100644 --- a/e2e/jest.setup.js +++ b/e2e/jest.setup.js @@ -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: { @@ -122,7 +122,13 @@ global.sampleAppConfig = { }, apis: { api1: { - base: { path: { action: { method: 'get' } } } + base: { + path: { + action: { + method: 'get' + } + } + } } }, dependencies: { dependency1: { location: '/adobeio/oauth' } } diff --git a/test/__fixtures__/sample-app/manifest.yml b/test/__fixtures__/sample-app/manifest.yml index 0e550c5..7570344 100644 --- a/test/__fixtures__/sample-app/manifest.yml +++ b/test/__fixtures__/sample-app/manifest.yml @@ -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