mirror of
https://github.com/IT4Change/gradido.git
synced 2025-12-13 07:45:54 +00:00
tests
This commit is contained in:
parent
9a834fa720
commit
e7062f2a55
@ -1,24 +1,23 @@
|
|||||||
/* eslint-disable @typescript-eslint/no-explicit-any */
|
/* eslint-disable @typescript-eslint/no-explicit-any */
|
||||||
/* eslint-disable @typescript-eslint/explicit-module-boundary-types */
|
/* eslint-disable @typescript-eslint/explicit-module-boundary-types */
|
||||||
|
|
||||||
import { createTestClient } from 'apollo-server-testing'
|
|
||||||
import createServer from '@/server/createServer'
|
|
||||||
import { resetEntity } from '@test/helpers'
|
|
||||||
import { Community as DbCommunity } from '@entity/Community'
|
import { Community as DbCommunity } from '@entity/Community'
|
||||||
import { Community } from '../model/Community'
|
import { Community } from '../model/Community'
|
||||||
|
import { testEnvironment } from '@test/helpers'
|
||||||
|
|
||||||
jest.mock('@/config')
|
// jest.mock('@/config')
|
||||||
|
|
||||||
let query: any
|
let query: any
|
||||||
|
|
||||||
// to do: We need a setup for the tests that closes the connection
|
// to do: We need a setup for the tests that closes the connection
|
||||||
let con: any
|
let con: any
|
||||||
|
let testEnv: any
|
||||||
|
|
||||||
beforeAll(async () => {
|
beforeAll(async () => {
|
||||||
const server = await createServer({})
|
testEnv = await testEnvironment()
|
||||||
con = server.con
|
query = testEnv.query
|
||||||
query = createTestClient(server.apollo).query
|
con = testEnv.con
|
||||||
resetEntity(DbCommunity)
|
await DbCommunity.clear()
|
||||||
})
|
})
|
||||||
|
|
||||||
afterAll(async () => {
|
afterAll(async () => {
|
||||||
@ -45,73 +44,85 @@ describe('CommunityResolver', () => {
|
|||||||
describe('getCommunities', () => {
|
describe('getCommunities', () => {
|
||||||
describe('with empty list', () => {
|
describe('with empty list', () => {
|
||||||
it('returns no community entry', async () => {
|
it('returns no community entry', async () => {
|
||||||
const result: Community[] = await query({ query: getCommunities })
|
// const result: Community[] = await query({ query: getCommunities })
|
||||||
expect(result.length).decimalEqual(0)
|
// expect(result.length).toEqual(0)
|
||||||
|
await expect(query({ query: getCommunities })).resolves.toMatchObject({
|
||||||
|
data: {
|
||||||
|
getCommunities: [],
|
||||||
|
},
|
||||||
|
})
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
|
|
||||||
describe('only home-communities entries', () => {
|
describe('only home-communities entries', () => {
|
||||||
beforeEach(() => {
|
let homeCom1: DbCommunity
|
||||||
const homeCom1 = DbCommunity.create()
|
let homeCom2: DbCommunity
|
||||||
|
let homeCom3: DbCommunity
|
||||||
|
|
||||||
|
beforeEach(async () => {
|
||||||
|
jest.clearAllMocks()
|
||||||
|
await DbCommunity.clear()
|
||||||
|
|
||||||
|
homeCom1 = DbCommunity.create()
|
||||||
homeCom1.foreign = false
|
homeCom1.foreign = false
|
||||||
homeCom1.publicKey = Buffer.from('publicKey-HomeCommunity')
|
homeCom1.publicKey = Buffer.from('publicKey-HomeCommunity')
|
||||||
homeCom1.apiVersion = '1_0'
|
homeCom1.apiVersion = '1_0'
|
||||||
homeCom1.endPoint = 'https://localhost'
|
homeCom1.endPoint = 'http://localhost'
|
||||||
homeCom1.createdAt = new Date()
|
homeCom1.createdAt = new Date()
|
||||||
DbCommunity.save(homeCom1)
|
await DbCommunity.insert(homeCom1)
|
||||||
|
|
||||||
const homeCom2 = DbCommunity.create()
|
homeCom2 = DbCommunity.create()
|
||||||
homeCom2.foreign = false
|
homeCom2.foreign = false
|
||||||
homeCom2.publicKey = Buffer.from('publicKey-HomeCommunity')
|
homeCom2.publicKey = Buffer.from('publicKey-HomeCommunity')
|
||||||
homeCom2.apiVersion = '1_1'
|
homeCom2.apiVersion = '1_1'
|
||||||
homeCom2.endPoint = 'https://localhost'
|
homeCom2.endPoint = 'http://localhost'
|
||||||
homeCom2.createdAt = new Date()
|
homeCom2.createdAt = new Date()
|
||||||
DbCommunity.save(homeCom2)
|
await DbCommunity.insert(homeCom2)
|
||||||
|
|
||||||
const homeCom3 = DbCommunity.create()
|
homeCom3 = DbCommunity.create()
|
||||||
homeCom3.foreign = false
|
homeCom3.foreign = false
|
||||||
homeCom3.publicKey = Buffer.from('publicKey-HomeCommunity')
|
homeCom3.publicKey = Buffer.from('publicKey-HomeCommunity')
|
||||||
homeCom3.apiVersion = '2_0'
|
homeCom3.apiVersion = '2_0'
|
||||||
homeCom3.endPoint = 'https://localhost'
|
homeCom3.endPoint = 'http://localhost'
|
||||||
homeCom3.createdAt = new Date()
|
homeCom3.createdAt = new Date()
|
||||||
DbCommunity.save(homeCom3)
|
await DbCommunity.insert(homeCom3)
|
||||||
})
|
})
|
||||||
|
|
||||||
it('returns three home-community entries', async () => {
|
it('returns three home-community entries', async () => {
|
||||||
await expect(query({ query: getCommunities })).resolves.toMatchObject({
|
await expect(query({ query: getCommunities })).resolves.toMatchObject({
|
||||||
data: {
|
data: {
|
||||||
communities: [
|
getCommunities: [
|
||||||
{
|
{
|
||||||
id: 1,
|
id: 1,
|
||||||
foreign: false,
|
foreign: homeCom1.foreign,
|
||||||
publicKey: expect.stringMatching(Buffer.from('publicKey-HomeCommunity').toString()),
|
publicKey: expect.stringMatching('publicKey-HomeCommunity'),
|
||||||
url: 'http://localhost/api/1_0',
|
url: expect.stringMatching('http://localhost/api/1_0'),
|
||||||
lastAnnouncedAt: null,
|
lastAnnouncedAt: null,
|
||||||
verifiedAt: null,
|
verifiedAt: null,
|
||||||
lastErrorAt: null,
|
lastErrorAt: null,
|
||||||
createdAt: expect.any(Date),
|
createdAt: homeCom1.createdAt.toISOString(),
|
||||||
updatedAt: null,
|
updatedAt: null,
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
id: 2,
|
id: 2,
|
||||||
foreign: false,
|
foreign: homeCom2.foreign,
|
||||||
publicKey: expect.stringMatching(Buffer.from('publicKey-HomeCommunity').toString()),
|
publicKey: expect.stringMatching('publicKey-HomeCommunity'),
|
||||||
url: 'http://localhost/api/1_1',
|
url: expect.stringMatching('http://localhost/api/1_1'),
|
||||||
lastAnnouncedAt: null,
|
lastAnnouncedAt: null,
|
||||||
verifiedAt: null,
|
verifiedAt: null,
|
||||||
lastErrorAt: null,
|
lastErrorAt: null,
|
||||||
createdAt: expect.any(Date),
|
createdAt: homeCom2.createdAt.toISOString(),
|
||||||
updatedAt: null,
|
updatedAt: null,
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
id: 3,
|
id: 3,
|
||||||
foreign: false,
|
foreign: homeCom3.foreign,
|
||||||
publicKey: expect.stringMatching(Buffer.from('publicKey-HomeCommunity').toString()),
|
publicKey: expect.stringMatching('publicKey-HomeCommunity'),
|
||||||
url: 'http://localhost/api/2_0',
|
url: expect.stringMatching('http://localhost/api/2_0'),
|
||||||
lastAnnouncedAt: null,
|
lastAnnouncedAt: null,
|
||||||
verifiedAt: null,
|
verifiedAt: null,
|
||||||
lastErrorAt: null,
|
lastErrorAt: null,
|
||||||
createdAt: expect.any(Date),
|
createdAt: homeCom3.createdAt.toISOString(),
|
||||||
updatedAt: null,
|
updatedAt: null,
|
||||||
},
|
},
|
||||||
],
|
],
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user