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 search parser e2e suite
- Loading branch information
1 parent
1f91f53
commit b3223da
Showing
3 changed files
with
1,275 additions
and
2 deletions.
There are no files selected for viewing
1,138 changes: 1,138 additions & 0 deletions
1,138
...ms/tktrex/backend/__tests__/fixtures/search/812b7e93d62ad6fdde6630c34c5ecfe7720474bb.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: "search"', () => { | ||
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 Search', () => { | ||
jest.setTimeout(20 * 1000); | ||
|
||
const history = readFixtureJSONPaths( | ||
path.resolve(__dirname, 'fixtures/search') | ||
); | ||
|
||
test.each(history)( | ||
'Should correctly parse "search" 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