I have a question. Now am working on gql + test e2e (i'm very new for test e2e) How can I test create mutaion
here is my categoryProduct.e2e-spec.ts
describe('AppController (e2e)', () => {
let app: INestApplication
let apolloClient: ApolloServerTestClient
beforeEach(async () => {
const moduleFixture: TestingModule = await Test.createTestingModule({
imports: [AppModule],
}).compile()
app = moduleFixture.createNestApplication()
await app.init()
const module: GraphQLModule = moduleFixture.get<GraphQLModule>(
GraphQLModule,
)
// apolloServer is protected, we need to cast module to any to get it
apolloClient = createTestClient((module as any).apolloServer)
})
const createCategoryProductObject = {
name: 'testData',
}
const createCategoryProductQuery = `mutation {
createCategoryProduct(input: ${createCategoryProductObject}) {
name
}
}`
it('getAllCategoryProduct', async () => {
const { query } = apolloClient
const result: any = await query({
query: gql`
query {
getAllCategoryProduct {
name
id
}
}
`,
})
console.log(result)
expect(result)
})
it('createCategoryProduct', async () => {
const { mutate } = apolloClient
const result: any = await mutate({
mutation: gql`
${createCategoryProductQuery}
`,
})
expect(result)
})
})
})
As you see in my getAllCategoryProduct I console.log(result) I get the right result and everything work fine but in createCategoryProduct I get an error
Unable to connect to the database. Retrying (1)...
AlreadyHasActiveConnectionError: Cannot create a new connection named "default", because connection with such name already exist and it now has an active connection session.
not sure why cannot connect database
Aucun commentaire:
Enregistrer un commentaire