Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Invalid test for function signatureUtils::getKeyFromCache #58

Closed
shazron opened this issue Aug 18, 2023 · 1 comment · Fixed by #65
Closed

Invalid test for function signatureUtils::getKeyFromCache #58

shazron opened this issue Aug 18, 2023 · 1 comment · Fixed by #65
Labels
bug Something isn't working

Comments

@shazron
Copy link
Member

shazron commented Aug 18, 2023

Function signatureUtils::getKeyFromCache :

/**
* Gets the public key from cache
*
* @param {*} state aio state lib instance
* @param {*} publicKeyFileNameAsKey public key file name in format pub-key-<random-uuid>.pem
* @returns {string} public key
*/
async function getKeyFromCache (state, publicKeyFileNameAsKey) {
try {
const keyObj = await state.get(publicKeyFileNameAsKey)
/**
* key json obj fetched from cache in below format
* {
* "value":"pem public key",
* "expiration":"24h timestamp"
* }
*/
return keyObj.value
} catch (error) {
logger.error('aio lib state get error due to => %s', error.message)
}
return null
}

On error, the function returns null, and never rethrows an Error.

The test "Test Get Key from Cache -> get key from cache throws" in signatureUtils.test.js is an invalid test since the tested function will never throw an error. In fact the test is bogus - it doesn't really test the return value or catch the function's error - it tests an error that it sets up itself.

The test is here:

describe('Test Get Key from Cache', () => {
it('get key from cache throws', async () => {
await signatureUtils.getKeyFromCache('state', 'invalid-url')
.then(res => {
throw new Error('lib state get error')
})
.catch(e => {
// eslint-disable-next-line jest/no-conditional-expect
expect(e instanceof Error).toBe(true)
// eslint-disable-next-line jest/no-conditional-expect
expect(e.message).toEqual('lib state get error')
})
})

@shazron shazron added the bug Something isn't working label Aug 18, 2023
@aiojbot
Copy link
Collaborator

aiojbot commented Aug 18, 2023

JIRA issue created: https://jira.corp.adobe.com/browse/ACNA-2499

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
2 participants