This repository has been archived by the owner on Aug 15, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 15
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
test(tk:backend): defined profile parser e2e suite
- Loading branch information
1 parent
f0db578
commit b0a0d05
Showing
7 changed files
with
183 additions
and
25 deletions.
There are no files selected for viewing
30 changes: 30 additions & 0 deletions
30
...s/tktrex/backend/__tests__/fixtures/profile/876a43574215629696bccb876a6f7660d3dc2dc9.json
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,125 @@ | ||
import { | ||
readFixtureJSON, | ||
readFixtureJSONPaths, | ||
runParserTest, | ||
} from '@shared/test/utils/parser.utils'; | ||
import { v4 as uuid } from 'uuid'; | ||
import { TKMetadata } from '@tktrex/shared/models'; | ||
import { parsers } from '@tktrex/shared/parser/parsers'; | ||
import base58 from 'bs58'; | ||
import { parseISO, subMinutes } from 'date-fns'; | ||
import path from 'path'; | ||
import nacl from 'tweetnacl'; | ||
import { GetTest, Test } from '../test/Test'; | ||
import { | ||
addDom, | ||
getLastHTMLs, | ||
getMetadata, | ||
getMetadataSchema, | ||
getSourceSchema, | ||
parserConfig, | ||
updateMetadataAndMarkHTML, | ||
} from '../lib/parser'; | ||
import { HTMLSource } from '@tktrex/shared/parser/source'; | ||
import { toMetadata } from '@tktrex/shared/parser/metadata'; | ||
|
||
describe('Parser: "profile"', () => { | ||
let appTest: Test; | ||
const newKeypair = nacl.sign.keyPair(); | ||
const publicKey = base58.encode(newKeypair.publicKey); | ||
|
||
let db: any; | ||
beforeAll(async () => { | ||
appTest = await GetTest(); | ||
|
||
db = { | ||
api: appTest.mongo3, | ||
read: appTest.mongo, | ||
write: appTest.mongo, | ||
}; | ||
}); | ||
|
||
afterEach(async () => { | ||
await appTest.mongo3.deleteMany( | ||
appTest.mongo, | ||
appTest.config.get('schema').htmls, | ||
{ | ||
publicKey: { | ||
$eq: publicKey, | ||
}, | ||
} | ||
); | ||
}); | ||
|
||
describe('Nature Profile', () => { | ||
jest.setTimeout(20 * 1000); | ||
|
||
const history = readFixtureJSONPaths( | ||
path.resolve(__dirname, 'fixtures/profile') | ||
); | ||
|
||
test.each(history)( | ||
'Should correctly parse "profile" contribution from path %s', | ||
async (fixturePath) => { | ||
const { sources: _sources, metadata } = readFixtureJSON( | ||
fixturePath, | ||
publicKey | ||
); | ||
const sources = _sources.map((s: any) => ({ | ||
html: { | ||
...s, | ||
id: uuid(), | ||
clientTime: parseISO(s.clientTime ?? new Date().toISOString()), | ||
savingTime: subMinutes(new Date(), 2), | ||
}, | ||
supporter: { version: process.env.VERSION }, | ||
})); | ||
|
||
await runParserTest({ | ||
name: 'native-parser', | ||
log: appTest.logger, | ||
parsers: parsers, | ||
db, | ||
codecs: { | ||
contribution: HTMLSource, | ||
metadata: TKMetadata.TKMetadata, | ||
}, | ||
addDom, | ||
sourceSchema: getSourceSchema(), | ||
metadataSchema: getMetadataSchema(), | ||
getEntryId: (e) => e.html.id, | ||
getEntryDate: (e) => e.html.savingTime, | ||
getEntryNatureType: (e) => e.html.type, | ||
getContributions: getLastHTMLs(db), | ||
getMetadata: getMetadata(db), | ||
saveResults: updateMetadataAndMarkHTML(db), | ||
buildMetadata: toMetadata, | ||
config: parserConfig, | ||
expectSources: (receivedSources) => { | ||
receivedSources.forEach((s) => { | ||
expect((s as any).processed).toBe(true); | ||
}); | ||
}, | ||
expectMetadata: (receivedMetadata, expectedMetadata) => { | ||
const { | ||
_id: received_Id, | ||
id: receivedId, | ||
savingTime: savingTimeR, | ||
...receivedM | ||
} = receivedMetadata as any; | ||
|
||
const { | ||
_id: _received_Id, | ||
id: _receivedId, | ||
clientTime: clientTimeExp, | ||
savingTime: savingTimeExp, | ||
...expectedM | ||
} = expectedMetadata as any; | ||
|
||
expect(receivedM).toMatchObject(expectedM); | ||
}, | ||
})({ sources, metadata }); | ||
} | ||
); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters