Skip to content

Commit

Permalink
fix tests, fix bug
Browse files Browse the repository at this point in the history
  • Loading branch information
macrael committed Nov 1, 2023
1 parent 278cdec commit d691597
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 20 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -13,20 +13,25 @@ import {
createDBUsersWithFullData,
testCMSUser,
} from '../../testHelpers/userHelpers'
import { testLDService } from '../../testHelpers/launchDarklyHelpers'

describe('createQuestion', () => {
const mockLDService = testLDService({ ['rates-db-refactor']: true })
const cmsUser = testCMSUser()
beforeAll(async () => {
//Inserting a new CMS user, with division assigned, in postgres in order to create the question to user relationship.
await createDBUsersWithFullData([cmsUser])
})

it('returns question data after creation', async () => {
const stateServer = await constructTestPostgresServer()
const stateServer = await constructTestPostgresServer({
ldService: mockLDService,
})
const cmsServer = await constructTestPostgresServer({
context: {
user: cmsUser,
},
ldService: mockLDService,
})

const submittedPkg = await createAndSubmitTestHealthPlanPackage(
Expand All @@ -41,7 +46,7 @@ describe('createQuestion', () => {
expect(createdQuestion.question).toEqual(
expect.objectContaining({
id: expect.any(String),
pkgID: submittedPkg.id,
contractID: submittedPkg.id,
division: 'DMCO',
documents: [
{
Expand All @@ -54,11 +59,14 @@ describe('createQuestion', () => {
)
})
it('allows question creation on UNLOCKED and RESUBMITTED package', async () => {
const stateServer = await constructTestPostgresServer()
const stateServer = await constructTestPostgresServer({
ldService: mockLDService,
})
const cmsServer = await constructTestPostgresServer({
context: {
user: cmsUser,
},
ldService: mockLDService,
})

const submittedPkg = await createAndSubmitTestHealthPlanPackage(
Expand Down Expand Up @@ -104,7 +112,7 @@ describe('createQuestion', () => {
node: expect.objectContaining({
id: expect.any(String),
createdAt: expect.any(Date),
pkgID: submittedPkg.id,
contractID: submittedPkg.id,
division: 'DMCO',
documents: [
{
Expand All @@ -119,7 +127,7 @@ describe('createQuestion', () => {
node: expect.objectContaining({
id: expect.any(String),
createdAt: expect.any(Date),
pkgID: submittedPkg.id,
contractID: submittedPkg.id,
division: 'DMCO',
documents: [
{
Expand All @@ -144,11 +152,14 @@ describe('createQuestion', () => {
)
})
it('returns an error package status is DRAFT', async () => {
const stateServer = await constructTestPostgresServer()
const stateServer = await constructTestPostgresServer({
ldService: mockLDService,
})
const cmsServer = await constructTestPostgresServer({
context: {
user: cmsUser,
},
ldService: mockLDService,
})

const draftPkg = await createTestHealthPlanPackage(stateServer)
Expand All @@ -157,7 +168,7 @@ describe('createQuestion', () => {
query: CREATE_QUESTION,
variables: {
input: {
pkgID: draftPkg.id,
contractID: draftPkg.id,
documents: [
{
name: 'Test Question',
Expand All @@ -175,7 +186,9 @@ describe('createQuestion', () => {
)
})
it('returns an error if a state user attempts to create a question for a package', async () => {
const stateServer = await constructTestPostgresServer()
const stateServer = await constructTestPostgresServer({
ldService: mockLDService,
})
const submittedPkg = await createAndSubmitTestHealthPlanPackage(
stateServer
)
Expand All @@ -184,7 +197,7 @@ describe('createQuestion', () => {
query: CREATE_QUESTION,
variables: {
input: {
pkgID: submittedPkg.id,
contractID: submittedPkg.id,
documents: [
{
name: 'Test Question',
Expand All @@ -202,11 +215,14 @@ describe('createQuestion', () => {
)
})
it('returns error on invalid package id', async () => {
const stateServer = await constructTestPostgresServer()
const stateServer = await constructTestPostgresServer({
ldService: mockLDService,
})
const cmsServer = await constructTestPostgresServer({
context: {
user: cmsUser,
},
ldService: mockLDService,
})

await createAndSubmitTestHealthPlanPackage(stateServer)
Expand All @@ -215,7 +231,7 @@ describe('createQuestion', () => {
query: CREATE_QUESTION,
variables: {
input: {
pkgID: 'invalid-pkg-id',
contractID: 'invalid-pkg-id',
documents: [
{
name: 'Test Question',
Expand All @@ -229,19 +245,22 @@ describe('createQuestion', () => {
expect(createdQuestion.errors).toBeDefined()
expect(assertAnErrorCode(createdQuestion)).toBe('NOT_FOUND')
expect(assertAnError(createdQuestion).message).toBe(
`Issue finding a package with id invalid-pkg-id. Message: Package with id invalid-pkg-id does not exist`
`Package with id invalid-pkg-id does not exist`
)
})
it('returns error when CMS user division is unassigned', async () => {
const cmsUserWithNoDivision = testCMSUser({
divisionAssignment: undefined,
})
await createDBUsersWithFullData([cmsUserWithNoDivision])
const stateServer = await constructTestPostgresServer()
const stateServer = await constructTestPostgresServer({
ldService: mockLDService,
})
const cmsServer = await constructTestPostgresServer({
context: {
user: cmsUserWithNoDivision,
},
ldService: mockLDService,
})

await createAndSubmitTestHealthPlanPackage(stateServer)
Expand All @@ -250,7 +269,7 @@ describe('createQuestion', () => {
query: CREATE_QUESTION,
variables: {
input: {
pkgID: 'invalid-pkg-id',
contractID: 'invalid-pkg-id',
documents: [
{
name: 'Test Question',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -69,12 +69,8 @@ export function createQuestionResolver(
})
}

// Return error if package status is DRAFT
// TODO we should have a helper for this
if (
contractResult.revisions.length === 1 &&
contractResult.revisions[0].submitInfo === undefined
) {
// Return error if package status is DRAFT, contract will have no submitted revisions
if (contractResult.revisions.length === 0) {
const errMessage = `Issue creating question for health plan package. Message: Cannot create question for health plan package in DRAFT status`
logError('createQuestion', errMessage)
setErrorAttributesOnActiveSpan(errMessage, span)
Expand Down

0 comments on commit d691597

Please sign in to comment.