Skip to content

Commit

Permalink
GQL-87: Adding test
Browse files Browse the repository at this point in the history
  • Loading branch information
mandyparson committed Oct 28, 2024
1 parent 5d3ee83 commit ae3c45e
Showing 1 changed file with 40 additions and 1 deletion.
41 changes: 40 additions & 1 deletion src/permissions/__tests__/fallbackError.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ const contextValue = {
}

describe('fallbackError', () => {
test('throws an error with the requestId present', async () => {
test('throws an error with the requestId present (cmr-error)', async () => {
vi.spyOn(hasPermission, 'hasPermission').mockResolvedValue(true)

const server = setupServer()
Expand Down Expand Up @@ -68,6 +68,45 @@ describe('fallbackError', () => {
contextValue
})

expect(result.body.singleResult.errors[0].message).toEqual('Cannot destructure property \'code\' of \'((cov_1is6xnfz3i(...).s[4]++) , extensions)\' as it is undefined.')

Check failure on line 71 in src/permissions/__tests__/fallbackError.test.js

View workflow job for this annotation

GitHub Actions / jest (lts/hydrogen)

src/permissions/__tests__/fallbackError.test.js > fallbackError > throws an error with the requestId present (cmr-error)

AssertionError: expected 'Cannot destructure property \'code\' …' to deeply equal 'Cannot destructure property \'code\' …' - Expected + Received - Cannot destructure property 'code' of '((cov_1is6xnfz3i(...).s[4]++) , extensions)' as it is undefined. + Cannot destructure property 'code' of '((cov_1vlfoo4cq6(...).s[4]++) , extensions)' as it is undefined. ❯ src/permissions/__tests__/fallbackError.test.js:71:56
})

test('throws a general error for non-cmr error', async () => {
vi.spyOn(hasPermission, 'hasPermission').mockResolvedValue(true)

const server = setupServer()

const query = gql`
query Groups (
$params: GroupsInput
) {
groups (
params: $params
) {
count
items {
id
name
description
tag
}
}
}
`

const variables = {
params: {
tags: ['other']
}
}

const result = await server.executeOperation({
query,
variables
}, {
contextValue
})

expect(result.body.singleResult.errors[0].message).toEqual('An unknown error occurred. Please refer to the ID mock-request-id when contacting Earthdata Operations (support@earthdata.nasa.gov).')

Check failure on line 110 in src/permissions/__tests__/fallbackError.test.js

View workflow job for this annotation

GitHub Actions / jest (lts/hydrogen)

src/permissions/__tests__/fallbackError.test.js > fallbackError > throws a general error for non-cmr error

AssertionError: expected 'Cannot destructure property \'code\' …' to deeply equal 'An unknown error occurred. Please ref…' - Expected + Received - An unknown error occurred. Please refer to the ID mock-request-id when contacting Earthdata Operations (support@earthdata.nasa.gov). + Cannot destructure property 'code' of '((cov_1vlfoo4cq6(...).s[4]++) , extensions)' as it is undefined. ❯ src/permissions/__tests__/fallbackError.test.js:110:56
})
})

0 comments on commit ae3c45e

Please sign in to comment.