Skip to content

Commit 43e8ee1

Browse files
committed
coverage 100%
1 parent c9d83f4 commit 43e8ee1

File tree

2 files changed

+50
-11
lines changed

2 files changed

+50
-11
lines changed

src/utils.js

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ const globby = require('globby')
2121
const path = require('path')
2222
const archiver = require('archiver')
2323
// this is a static list that comes from here: https://developer.adobe.com/runtime/docs/guides/reference/runtimes/
24-
const SupportedRuntimes = ['nodejs:10', 'nodejs:12', 'nodejs:14', 'nodejs:16', 'nodejs:18']
24+
const SupportedRuntimes = ['sequence', 'nodejs:10', 'nodejs:12', 'nodejs:14', 'nodejs:16', 'nodejs:18']
2525
const DEFAULT_PACKAGE_RESERVED_NAME = 'default'
2626

2727
/**
@@ -1491,12 +1491,12 @@ async function deployPackage (entities, ow, logger, imsOrgId) {
14911491

14921492
for (const action of entities.actions) {
14931493
const retAction = cloneDeep(action)
1494-
if (!SupportedRuntimes.includes(retAction?.exec?.kind)) {
1495-
const supportedServerRuntimes = ( await getSupportedServerRuntimes(apihost) ).sort().reverse()
1494+
if (retAction?.exec?.kind && !isSupportedActionKind(retAction)) {
1495+
const supportedServerRuntimes = (await getSupportedServerRuntimes(apihost)).sort().reverse()
14961496
if (supportedServerRuntimes.includes(retAction?.exec?.kind)) {
14971497
aioLogger.debug(`Local node kinds mismatch with server supported kinds ${supportedServerRuntimes}`)
14981498
} else {
1499-
throw new Error(`Unsupported node version '${retAction.exec.kind}' in action ${retAction.name}.\n` +
1499+
throw new Error(`Unsupported node version '${retAction?.exec?.kind}' in action ${retAction.name}.\n` +
15001500
`Supported runtimes on ${apihost}: ${supportedServerRuntimes}`)
15011501
}
15021502
}

test/utils.test.js

Lines changed: 46 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -765,12 +765,41 @@ describe('deployPackage', () => {
765765
json: () => result
766766
})
767767

768-
const supportedClientRuntimes = ['nodejs:10', 'nodejs:12', 'nodejs:14', 'nodejs:16', 'nodejs:18']
769-
const supportedServerRuntimes = await utils.getSupportedServerRuntimes(initOptions.apihost)
768+
await expect(() =>
769+
utils.deployPackage(JSON.parse(fs.readFileSync('/basic_manifest_unsupported_kind.json')), ow, mockLogger, imsOrgId)
770+
).rejects.toThrow(/Unsupported node version 'nodejs:8/)
771+
})
772+
773+
test('basic manifest - local `kind` list missing', async () => {
774+
const imsOrgId = 'MyIMSOrgId'
775+
const mockLogger = jest.fn()
776+
const actionOptions = {
777+
apiKey: 'my-key',
778+
namespace: 'my-namespace'
779+
}
780+
const initOptions = {
781+
apihost: 'https://adobeio.adobeioruntime.net'
782+
}
783+
ow.mockResolvedProperty('actions.client.options', actionOptions)
784+
ow.mockResolvedProperty(owInitOptions, initOptions)
785+
786+
const result = {
787+
runtimes: {
788+
nodejs: [
789+
{ kind: 'nodejs:8' }, // server says it supports nodejs:8!
790+
{ kind: 'nodejs:16' }
791+
]
792+
}
793+
}
794+
mockFetch.mockResolvedValue({
795+
ok: true,
796+
status: 200,
797+
json: () => result
798+
})
770799

771800
await expect(() =>
772801
utils.deployPackage(JSON.parse(fs.readFileSync('/basic_manifest_unsupported_kind.json')), ow, mockLogger, imsOrgId)
773-
).rejects.toThrow(`Unsupported node version 'nodejs:8' in action hello/helloAction. Supported versions are ${supportedClientRuntimes}. Supported runtimes on ${initOptions.apihost}: ${supportedServerRuntimes}`)
802+
).not.toThrow()
774803
})
775804

776805
test('basic manifest (fetch error)', async () => {
@@ -2243,10 +2272,20 @@ describe('validateActionRuntime', () => {
22432272
expect(() => utils.validateActionRuntime({ exec: { kind: 'nodejs:16' } })).not.toThrow()
22442273
expect(() => utils.validateActionRuntime({ exec: { kind: 'nodejs:18' } })).not.toThrow()
22452274
})
2246-
2247-
test('invalid nodejs version', async () => {
2248-
const func = () => utils.validateActionRuntime({ exec: { kind: 'nodejs:17' } })
2249-
expect(func).toThrowError('Unsupported node version')
2275+
test('no exec', () => {
2276+
expect(utils.validateActionRuntime({})).toBeUndefined()
2277+
})
2278+
test('no runtime kind', () => {
2279+
expect(utils.validateActionRuntime({ exec: {} })).toBeUndefined()
2280+
})
2281+
test('valid runtime kind', () => {
2282+
expect(utils.validateActionRuntime({ exec: { kind: 'nodejs:14' } })).toBeUndefined()
2283+
})
2284+
test('valid runtime kind - toLower', () => {
2285+
expect(() => utils.validateActionRuntime({ exec: { kind: 'NODEJS:14' } })).toThrowError('Unsupported node version')
2286+
})
2287+
test('invalid nodejs version', () => {
2288+
expect(() => utils.validateActionRuntime({ exec: { kind: 'nodejs:17' } })).toThrowError('Unsupported node version')
22502289
})
22512290

22522291
test('dumpActionsBuiltInfo might catch some errors under unlikely conditions', async () => {

0 commit comments

Comments
 (0)