mirror of
https://github.com/IT4Change/gradido.git
synced 2025-12-13 07:45:54 +00:00
179 lines
5.8 KiB
TypeScript
179 lines
5.8 KiB
TypeScript
/* eslint-disable @typescript-eslint/no-unsafe-member-access */
|
|
/* eslint-disable @typescript-eslint/unbound-method */
|
|
/* eslint-disable @typescript-eslint/no-unsafe-assignment */
|
|
/* eslint-disable @typescript-eslint/no-unsafe-call */
|
|
/* eslint-disable @typescript-eslint/no-explicit-any */
|
|
/* eslint-disable @typescript-eslint/explicit-module-boundary-types */
|
|
|
|
import { Connection } from '@dbTools/typeorm'
|
|
import { FederatedCommunity as DbFederatedCommunity } from '@entity/FederatedCommunity'
|
|
import { ApolloServerTestClient } from 'apollo-server-testing'
|
|
|
|
import { testEnvironment, cleanDB } from '@test/helpers'
|
|
import { logger } from '@test/testSetup'
|
|
|
|
import { validateCommunities } from './validateCommunities'
|
|
|
|
let con: Connection
|
|
let testEnv: {
|
|
mutate: ApolloServerTestClient['mutate']
|
|
query: ApolloServerTestClient['query']
|
|
con: Connection
|
|
}
|
|
|
|
beforeAll(async () => {
|
|
testEnv = await testEnvironment(logger)
|
|
con = testEnv.con
|
|
await cleanDB()
|
|
})
|
|
|
|
afterAll(async () => {
|
|
// await cleanDB()
|
|
await con.close()
|
|
})
|
|
|
|
describe('validate Communities', () => {
|
|
/*
|
|
describe('start validation loop', () => {
|
|
beforeEach(async () => {
|
|
jest.clearAllMocks()
|
|
startValidateCommunities(0)
|
|
})
|
|
|
|
it('logs loop started', () => {
|
|
expect(logger.info).toBeCalledWith(
|
|
`Federation: startValidateCommunities loop with an interval of 0 ms...`,
|
|
)
|
|
})
|
|
})
|
|
*/
|
|
describe('start validation logic without loop', () => {
|
|
beforeEach(async () => {
|
|
jest.clearAllMocks()
|
|
await validateCommunities()
|
|
})
|
|
|
|
it('logs zero communities found', () => {
|
|
expect(logger.debug).toBeCalledWith(`Federation: found 0 dbCommunities`)
|
|
})
|
|
|
|
describe('with one Community of api 1_0', () => {
|
|
beforeEach(async () => {
|
|
const variables1 = {
|
|
publicKey: Buffer.from('11111111111111111111111111111111'),
|
|
apiVersion: '1_0',
|
|
endPoint: 'http//localhost:5001/api/',
|
|
lastAnnouncedAt: new Date(),
|
|
}
|
|
await DbFederatedCommunity.createQueryBuilder()
|
|
.insert()
|
|
.into(DbFederatedCommunity)
|
|
.values(variables1)
|
|
.orUpdate({
|
|
// eslint-disable-next-line camelcase
|
|
conflict_target: ['id', 'publicKey', 'apiVersion'],
|
|
overwrite: ['end_point', 'last_announced_at'],
|
|
})
|
|
.execute()
|
|
|
|
jest.clearAllMocks()
|
|
await validateCommunities()
|
|
})
|
|
|
|
it('logs one community found', () => {
|
|
expect(logger.debug).toBeCalledWith(`Federation: found 1 dbCommunities`)
|
|
})
|
|
it('logs requestGetPublicKey for community api 1_0 ', () => {
|
|
expect(logger.info).toBeCalledWith(
|
|
'Federation: getPublicKey from endpoint',
|
|
'http//localhost:5001/api/1_0/',
|
|
)
|
|
})
|
|
})
|
|
describe('with two Communities of api 1_0 and 1_1', () => {
|
|
beforeEach(async () => {
|
|
const variables2 = {
|
|
publicKey: Buffer.from('11111111111111111111111111111111'),
|
|
apiVersion: '1_1',
|
|
endPoint: 'http//localhost:5001/api/',
|
|
lastAnnouncedAt: new Date(),
|
|
}
|
|
await DbFederatedCommunity.createQueryBuilder()
|
|
.insert()
|
|
.into(DbFederatedCommunity)
|
|
.values(variables2)
|
|
.orUpdate({
|
|
conflict_target: ['id', 'publicKey', 'apiVersion'],
|
|
overwrite: ['end_point', 'last_announced_at'],
|
|
})
|
|
.execute()
|
|
|
|
jest.clearAllMocks()
|
|
await validateCommunities()
|
|
})
|
|
it('logs two communities found', () => {
|
|
expect(logger.debug).toBeCalledWith(`Federation: found 2 dbCommunities`)
|
|
})
|
|
it('logs requestGetPublicKey for community api 1_0 ', () => {
|
|
expect(logger.info).toBeCalledWith(
|
|
'Federation: getPublicKey from endpoint',
|
|
'http//localhost:5001/api/1_0/',
|
|
)
|
|
})
|
|
it('logs requestGetPublicKey for community api 1_1 ', () => {
|
|
expect(logger.info).toBeCalledWith(
|
|
'Federation: getPublicKey from endpoint',
|
|
'http//localhost:5001/api/1_1/',
|
|
)
|
|
})
|
|
})
|
|
describe('with three Communities of api 1_0, 1_1 and 2_0', () => {
|
|
let dbCom: DbFederatedCommunity
|
|
beforeEach(async () => {
|
|
const variables3 = {
|
|
publicKey: Buffer.from('11111111111111111111111111111111'),
|
|
apiVersion: '2_0',
|
|
endPoint: 'http//localhost:5001/api/',
|
|
lastAnnouncedAt: new Date(),
|
|
}
|
|
await DbFederatedCommunity.createQueryBuilder()
|
|
.insert()
|
|
.into(DbFederatedCommunity)
|
|
.values(variables3)
|
|
.orUpdate({
|
|
conflict_target: ['id', 'publicKey', 'apiVersion'],
|
|
overwrite: ['end_point', 'last_announced_at'],
|
|
})
|
|
.execute()
|
|
dbCom = await DbFederatedCommunity.findOneOrFail({
|
|
where: { publicKey: variables3.publicKey, apiVersion: variables3.apiVersion },
|
|
})
|
|
jest.clearAllMocks()
|
|
await validateCommunities()
|
|
})
|
|
it('logs three community found', () => {
|
|
expect(logger.debug).toBeCalledWith(`Federation: found 3 dbCommunities`)
|
|
})
|
|
it('logs requestGetPublicKey for community api 1_0 ', () => {
|
|
expect(logger.info).toBeCalledWith(
|
|
'Federation: getPublicKey from endpoint',
|
|
'http//localhost:5001/api/1_0/',
|
|
)
|
|
})
|
|
it('logs requestGetPublicKey for community api 1_1 ', () => {
|
|
expect(logger.info).toBeCalledWith(
|
|
'Federation: getPublicKey from endpoint',
|
|
'http//localhost:5001/api/1_1/',
|
|
)
|
|
})
|
|
it('logs unsupported api for community with api 2_0 ', () => {
|
|
expect(logger.warn).toBeCalledWith(
|
|
'Federation: dbCom with unsupported apiVersion',
|
|
dbCom.endPoint,
|
|
'2_0',
|
|
)
|
|
})
|
|
})
|
|
})
|
|
})
|