mirror of
https://github.com/IT4Change/gradido.git
synced 2025-12-13 07:45:54 +00:00
feat: Setup Unit Tests for Resolvers
This commit is contained in:
parent
501a23ede1
commit
2696a7eb5b
@ -18,6 +18,7 @@
|
|||||||
"dependencies": {
|
"dependencies": {
|
||||||
"@types/jest": "^27.0.2",
|
"@types/jest": "^27.0.2",
|
||||||
"apollo-server-express": "^2.25.2",
|
"apollo-server-express": "^2.25.2",
|
||||||
|
"apollo-server-testing": "^2.25.2",
|
||||||
"axios": "^0.21.1",
|
"axios": "^0.21.1",
|
||||||
"class-validator": "^0.13.1",
|
"class-validator": "^0.13.1",
|
||||||
"cors": "^2.8.5",
|
"cors": "^2.8.5",
|
||||||
|
|||||||
39
backend/src/graphql/resolver/CommunityResolver.test.ts
Normal file
39
backend/src/graphql/resolver/CommunityResolver.test.ts
Normal file
@ -0,0 +1,39 @@
|
|||||||
|
import { createTestClient } from 'apollo-server-testing'
|
||||||
|
import createTestServer from '../../test-server'
|
||||||
|
|
||||||
|
let query: any
|
||||||
|
|
||||||
|
beforeAll(async () => {
|
||||||
|
const apollo = createTestServer()
|
||||||
|
|
||||||
|
query = createTestClient(await apollo).query
|
||||||
|
})
|
||||||
|
|
||||||
|
describe('CommunityResolver', () => {
|
||||||
|
|
||||||
|
const getCommunityInfoQuery = `
|
||||||
|
query {
|
||||||
|
getCommunityInfo() {
|
||||||
|
name
|
||||||
|
description
|
||||||
|
url
|
||||||
|
registerUrl
|
||||||
|
}
|
||||||
|
}
|
||||||
|
`
|
||||||
|
|
||||||
|
describe('getCommunityInfo', () => {
|
||||||
|
it('returns the default values', async () => {
|
||||||
|
await expect(query({ query: getCommunityInfoQuery })).resolves.toMatchObject({
|
||||||
|
data: {
|
||||||
|
getCommunityInfo: {
|
||||||
|
name: 'Gradido Entwicklung',
|
||||||
|
description: 'Die lokale Entwicklungsumgebung von Gradido.',
|
||||||
|
url: 'http://localhost/vue/',
|
||||||
|
registerUrl: 'http://localhost/vue/register',
|
||||||
|
},
|
||||||
|
},
|
||||||
|
})
|
||||||
|
})
|
||||||
|
})
|
||||||
|
})
|
||||||
@ -19,9 +19,7 @@ export class CommunityResolver {
|
|||||||
|
|
||||||
@Query(() => [Community])
|
@Query(() => [Community])
|
||||||
async communities(): Promise<Community[]> {
|
async communities(): Promise<Community[]> {
|
||||||
const communities: Community[] = []
|
return [
|
||||||
|
|
||||||
communities.push(
|
|
||||||
new Community({
|
new Community({
|
||||||
id: 1,
|
id: 1,
|
||||||
name: 'Gradido Entwicklung',
|
name: 'Gradido Entwicklung',
|
||||||
@ -43,7 +41,6 @@ export class CommunityResolver {
|
|||||||
url: 'https://gradido.net',
|
url: 'https://gradido.net',
|
||||||
registerUrl: 'https://gdd1.gradido.com/vue/register-community',
|
registerUrl: 'https://gdd1.gradido.com/vue/register-community',
|
||||||
}),
|
}),
|
||||||
)
|
]
|
||||||
return communities
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
29
backend/src/test-server.ts
Normal file
29
backend/src/test-server.ts
Normal file
@ -0,0 +1,29 @@
|
|||||||
|
import { ApolloServer } from 'apollo-server-express'
|
||||||
|
import express from 'express'
|
||||||
|
import cors from './server/cors'
|
||||||
|
import context from './server/context'
|
||||||
|
import plugins from './server/plugins'
|
||||||
|
import CONFIG from './config'
|
||||||
|
|
||||||
|
// graphql
|
||||||
|
import schema from './graphql/schema'
|
||||||
|
|
||||||
|
const createTestServer = async () => {
|
||||||
|
// Express Server
|
||||||
|
const server = express()
|
||||||
|
|
||||||
|
// cors
|
||||||
|
server.use(cors)
|
||||||
|
|
||||||
|
// Apollo Server
|
||||||
|
const apollo = new ApolloServer({
|
||||||
|
schema: await schema(),
|
||||||
|
playground: CONFIG.GRAPHIQL,
|
||||||
|
context,
|
||||||
|
plugins,
|
||||||
|
})
|
||||||
|
apollo.applyMiddleware({ app: server })
|
||||||
|
return apollo
|
||||||
|
}
|
||||||
|
|
||||||
|
export default createTestServer
|
||||||
@ -1328,6 +1328,13 @@ apollo-server-plugin-base@^0.13.0:
|
|||||||
dependencies:
|
dependencies:
|
||||||
apollo-server-types "^0.9.0"
|
apollo-server-types "^0.9.0"
|
||||||
|
|
||||||
|
apollo-server-testing@^2.25.2:
|
||||||
|
version "2.25.2"
|
||||||
|
resolved "https://registry.yarnpkg.com/apollo-server-testing/-/apollo-server-testing-2.25.2.tgz#0043e98b1a03720352e94b409215fb4782ae2e50"
|
||||||
|
integrity sha512-HjQV9wPbi/ZqpRbyyhNwCbaDnfjDM0hTRec5TOoOjurEZ/vh4hTPHwGkDZx3kbcWowhGxe2qoHM6KANSB/SxuA==
|
||||||
|
dependencies:
|
||||||
|
apollo-server-core "^2.25.2"
|
||||||
|
|
||||||
apollo-server-types@^0.9.0:
|
apollo-server-types@^0.9.0:
|
||||||
version "0.9.0"
|
version "0.9.0"
|
||||||
resolved "https://registry.npmjs.org/apollo-server-types/-/apollo-server-types-0.9.0.tgz"
|
resolved "https://registry.npmjs.org/apollo-server-types/-/apollo-server-types-0.9.0.tgz"
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user