diff --git a/dht-node/jest.config.js b/dht-node/jest.config.js index fa00ed868..0b83d8edd 100644 --- a/dht-node/jest.config.js +++ b/dht-node/jest.config.js @@ -6,7 +6,7 @@ module.exports = { collectCoverageFrom: ['src/**/*.ts', '!**/node_modules/**', '!src/seeds/**', '!build/**'], coverageThreshold: { global: { - lines: 80, + lines: 83, }, }, setupFiles: ['/test/testSetup.ts'], diff --git a/dht-node/src/dht_node/index.test.ts b/dht-node/src/dht_node/index.test.ts index f2f54f567..46ae0e220 100644 --- a/dht-node/src/dht_node/index.test.ts +++ b/dht-node/src/dht_node/index.test.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'), ) diff --git a/dht-node/src/dht_node/index.ts b/dht-node/src/dht_node/index.ts index dcb4db6be..bd9c95a7e 100644 --- a/dht-node/src/dht_node/index.ts +++ b/dht-node/src/dht_node/index.ts @@ -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 { - 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 { try { // check for existing homeCommunity entry @@ -243,24 +228,22 @@ export async function writeHomeCommunityEntry(pubKey: string): Promise { } 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)}`) }