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
ff65a76
commit d2e7b1b
Showing
4 changed files
with
1,325 additions
and
25 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,142 @@ | ||
import { | ||
readFixtureJSON, | ||
readFixtureJSONPaths, | ||
runParserTest, | ||
} from '@shared/test/utils/parser.utils'; | ||
import { TKMetadata } from '@tktrex/shared/models'; | ||
import { toMetadata } from '@tktrex/shared/parser/metadata'; | ||
import { parsers } from '@tktrex/shared/parser/parsers'; | ||
import { HTMLSource } from '@tktrex/shared/parser/source'; | ||
import base58 from 'bs58'; | ||
import { parseISO, subMinutes } from 'date-fns'; | ||
import path from 'path'; | ||
import nacl from 'tweetnacl'; | ||
import { v4 as uuid } from 'uuid'; | ||
import { | ||
addDom, | ||
getLastHTMLs, | ||
getMetadata, | ||
getMetadataSchema, | ||
getSourceSchema, | ||
parserConfig, | ||
updateMetadataAndMarkHTML, | ||
} from '../lib/parser'; | ||
import { GetTest, Test } from '../test/Test'; | ||
|
||
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: TKMetadata.SearchMetadata, | ||
expectedMetadata: TKMetadata.SearchMetadata | ||
) => { | ||
const { | ||
_id: received_Id, | ||
id: receivedId, | ||
clientTime: clientTimeR, | ||
savingTime: savingTimeR, | ||
results: resultsR, | ||
...receivedM | ||
} = receivedMetadata; | ||
|
||
const { | ||
_id: _received_Id, | ||
id: _receivedId, | ||
clientTime: clientTimeExp, | ||
savingTime: savingTimeExp, | ||
results: resultsExp, | ||
...expectedM | ||
} = expectedMetadata; | ||
|
||
expect(receivedM).toMatchObject(expectedM); | ||
expect( | ||
resultsR.map((r) => ({ | ||
...r, | ||
publishingDate: parseISO(r.publishingDate), | ||
})) | ||
).toMatchObject( | ||
resultsExp.map((r) => ({ | ||
...r, | ||
publishingDate: expect.any(Date), | ||
})) | ||
); | ||
}, | ||
})({ 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