Skip to content
This repository has been archived by the owner on Nov 24, 2023. It is now read-only.

Commit

Permalink
test: Add first ability test
Browse files Browse the repository at this point in the history
  • Loading branch information
mithi committed Oct 31, 2020
1 parent 77a405f commit f3b1963
Show file tree
Hide file tree
Showing 2 changed files with 80 additions and 0 deletions.
35 changes: 35 additions & 0 deletions tests/resolvers/__snapshots__/ABILITY_BY_ID.ts
@@ -0,0 +1,35 @@
const result = () => {
return `
Object {
"data": Object {
"abilityById": Object {
"abilityDescription": "Fills a zone with powerful healing roots. Allies over it heal over 4 seconds. Each upgrade level increases HP healed",
"abilityId": 85,
"abilityName": "Healing Roots",
"kingdom": "KRV",
"levelCosts": Array [
130,
130,
130,
],
"numberOfLevels": 3,
"totalAbilityCost": 390,
"totalCostWithTowers": 1290,
"towerId": 104,
"towerImageUrl": "https://storage.googleapis.com/kingdom-rush-towers.appspot.com/krv-shaman4.png",
"towerName": "orc shaman, 4",
"towerType": "MAGE",
},
},
"errors": undefined,
"extensions": undefined,
"http": Object {
"headers": Headers {
Symbol(map): Object {},
},
},
}
`
}

export default result
45 changes: 45 additions & 0 deletions tests/resolvers/ability.test.ts
@@ -0,0 +1,45 @@
import { createConnection, getConnection } from "typeorm"
import { buildSchema } from "type-graphql"
import { AbilityResolver } from "../../src/resolvers/AbilityResolver"
import { ApolloServer, gql } from "apollo-server"
import { createTestClient } from "apollo-server-testing"
import ABILITY_BY_ID_RESULT from "./__snapshots__/ABILITY_BY_ID"
import { DocumentNode } from "graphql"

beforeAll(async () => {
await createConnection("test")
})

afterAll(async () => {
await getConnection("test").close()
})

const executeTest = async (testQuery: DocumentNode, correctAnswer: string) => {
const schema = await buildSchema({ resolvers: [AbilityResolver] })
const { query } = createTestClient(new ApolloServer({ schema }))

const result = await query({ query: testQuery })
expect(result).toMatchInlineSnapshot(correctAnswer)
}

test("1. Be able to get ability data by its id", async () => {
const testQuery = gql`
{
abilityById(id: 85) {
abilityDescription
abilityId
abilityName
kingdom
levelCosts
numberOfLevels
totalAbilityCost
totalCostWithTowers
towerId
towerImageUrl
towerName
towerType
}
}
`
await executeTest(testQuery, ABILITY_BY_ID_RESULT())
})

0 comments on commit f3b1963

Please sign in to comment.