mirror of
https://github.com/IT4Change/gradido.git
synced 2025-12-12 23:35:50 +00:00
clean code after trying to avoid testframework timing problems
This commit is contained in:
parent
827c719eba
commit
4308dc7329
@ -6,7 +6,7 @@ module.exports = {
|
||||
collectCoverageFrom: ['src/**/*.ts', '!**/node_modules/**', '!src/seeds/**', '!build/**'],
|
||||
coverageThreshold: {
|
||||
global: {
|
||||
lines: 80,
|
||||
lines: 83,
|
||||
},
|
||||
},
|
||||
setupFiles: ['<rootDir>/test/testSetup.ts'],
|
||||
|
||||
@ -163,7 +163,7 @@ describe('federation', () => {
|
||||
})
|
||||
|
||||
describe('home community', () => {
|
||||
it('one in communities', async () => {
|
||||
it('one in table communities', async () => {
|
||||
const result = await DbCommunity.find({ foreign: false })
|
||||
expect(result).toEqual(
|
||||
expect.arrayContaining([
|
||||
@ -191,7 +191,7 @@ describe('federation', () => {
|
||||
expect(valUUID).toEqual(true)
|
||||
expect(verUUID).toEqual(4)
|
||||
})
|
||||
it('update the one in communities', async () => {
|
||||
it('update the one in table communities', async () => {
|
||||
const resultBefore = await DbCommunity.find({ foreign: false })
|
||||
expect(resultBefore).toHaveLength(1)
|
||||
const modifiedCom = DbCommunity.create()
|
||||
@ -230,8 +230,9 @@ describe('federation', () => {
|
||||
})
|
||||
})
|
||||
|
||||
// skipped because ot timing problems in testframework
|
||||
describe.skip('federated home community', () => {
|
||||
it('three in federated_communities', async () => {
|
||||
it('three in table federated_communities', async () => {
|
||||
const homeApiVersions: CommunityApi[] = await writeFederatedHomeCommunityEntries(
|
||||
keyPairMock.publicKey.toString('hex'),
|
||||
)
|
||||
|
||||
@ -199,7 +199,12 @@ export async function writeFederatedHomeCommunityEntries(pubKey: string): Promis
|
||||
// first remove privious existing homeCommunity entries
|
||||
DbFederatedCommunity.createQueryBuilder().delete().where({ foreign: false }).execute()
|
||||
for (let i = 0; i < homeApiVersions.length; i++) {
|
||||
await createFederatedCommunityEntity(homeApiVersions[i], pubKey)
|
||||
const homeCom = DbFederatedCommunity.create()
|
||||
homeCom.foreign = false
|
||||
homeCom.apiVersion = homeApiVersions[i].api
|
||||
homeCom.endPoint = homeApiVersions[i].url
|
||||
homeCom.publicKey = Buffer.from(pubKey)
|
||||
await DbFederatedCommunity.insert(homeCom)
|
||||
logger.info(
|
||||
`federation home-community inserted successfully: ${JSON.stringify(homeApiVersions[i])}`,
|
||||
)
|
||||
@ -210,26 +215,6 @@ export async function writeFederatedHomeCommunityEntries(pubKey: string): Promis
|
||||
return homeApiVersions
|
||||
}
|
||||
|
||||
async function createFederatedCommunityEntity(
|
||||
homeApi: CommunityApi,
|
||||
pubKey: string,
|
||||
): Promise<boolean> {
|
||||
try {
|
||||
const homeCom = DbFederatedCommunity.create()
|
||||
homeCom.foreign = false
|
||||
homeCom.apiVersion = homeApi.api
|
||||
homeCom.endPoint = homeApi.url
|
||||
homeCom.publicKey = Buffer.from(pubKey)
|
||||
|
||||
// this will NOT update the updatedAt column, to distingue between a normal update and the last announcement
|
||||
await DbFederatedCommunity.insert(homeCom)
|
||||
logger.debug(`federation home-community inserted successfully: ${JSON.stringify(homeCom)}`)
|
||||
} catch (err) {
|
||||
return false
|
||||
}
|
||||
return true
|
||||
}
|
||||
|
||||
export async function writeHomeCommunityEntry(pubKey: string): Promise<void> {
|
||||
try {
|
||||
// check for existing homeCommunity entry
|
||||
@ -243,24 +228,22 @@ export async function writeHomeCommunityEntry(pubKey: string): Promise<void> {
|
||||
}
|
||||
if (homeCom) {
|
||||
// simply update the existing entry, but it MUST keep the ID and UUID because of possible relations
|
||||
homeCom.publicKey = Buffer.from(pubKey) // pubKey.toString('hex')
|
||||
homeCom.publicKey = Buffer.from(pubKey)
|
||||
homeCom.url = CONFIG.FEDERATION_COMMUNITY_URL + '/api/'
|
||||
homeCom.name = CONFIG.COMMUNITY_NAME
|
||||
homeCom.description = CONFIG.COMMUNITY_DESCRIPTION
|
||||
// this will NOT update the updatedAt column, to distingue between a normal update and the last announcement
|
||||
await DbCommunity.save(homeCom)
|
||||
logger.info(`home-community updated successfully: ${JSON.stringify(homeCom)}`)
|
||||
} else {
|
||||
// insert a new homecommunity entry including a new ID and a new but ensured unique UUID
|
||||
homeCom = new DbCommunity()
|
||||
homeCom.foreign = false
|
||||
homeCom.publicKey = Buffer.from(pubKey) // pubKey.toString('hex')
|
||||
homeCom.publicKey = Buffer.from(pubKey)
|
||||
homeCom.communityUuid = await newCommunityUuid()
|
||||
homeCom.url = CONFIG.FEDERATION_COMMUNITY_URL + '/api/'
|
||||
homeCom.name = CONFIG.COMMUNITY_NAME
|
||||
homeCom.description = CONFIG.COMMUNITY_DESCRIPTION
|
||||
homeCom.creationDate = new Date()
|
||||
// this will NOT update the updatedAt column, to distingue between a normal update and the last announcement
|
||||
await DbCommunity.insert(homeCom)
|
||||
logger.info(`home-community inserted successfully: ${JSON.stringify(homeCom)}`)
|
||||
}
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user