Skip to content

Commit

Permalink
Schopp/uuids (#364)
Browse files Browse the repository at this point in the history
* Added uuids as fetch ids

* Fixed test

* feat(uuid): Added uuids as Fetch Ids
  • Loading branch information
Florian-Schopp authored May 15, 2023
1 parent f753f16 commit 00409d7
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 22 deletions.
2 changes: 1 addition & 1 deletion jest.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,6 @@ module.exports = {
roots: ['<rootDir>/test'],
testRegex: '/test/.*\\.(test|spec)?\\.(ts|tsx)$',
transform: { '^.+\\.(js|ts|tsx)?$': ['ts-jest', { isolatedModules: true }] },
transformIgnorePatterns: ['node_modules/(?!uuid)'],
transformIgnorePatterns: ['node_modules/(?!nanoid)'],
testEnvironment: 'jsdom'
}
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "node-jet",
"version": "3.0.3",
"version": "3.0.4",
"description": "Jet Realtime Message Bus for the Web. Daemon and Peer implementation.",
"url": "https://github.com/hbm/node-jet",
"author": {
Expand Down
52 changes: 32 additions & 20 deletions test/peer/peer.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -165,7 +165,12 @@ describe('Testing Peer', () => {
return true
})
peer.fetch(m).then(() => {
cbs['___f___1'](undefined, 'fooId3', { params: { path: 'foo' } })
Object.keys(cbs).forEach((key) => {
if (!['call', 'fetch_all', 'get', 'set'].includes(key)) {
cbs[key](undefined, 'fooId3', { params: { path: 'foo' } })
}
})

expect(fetchSpy).toBeCalledTimes(1)
done()
})
Expand Down Expand Up @@ -444,12 +449,14 @@ describe('Testing Peer', () => {
jest.spyOn(JsonRPC, 'default').mockImplementation(() => jsonrpc)
const peer = new Peer()
peer.fetch(new Fetcher()).catch((ex) => {
expect(sendSpy).toBeCalledWith('fetch', {
id: '___f___1',
path: {},
value: {},
sort: {}
})
expect(sendSpy).toBeCalledWith(
'fetch',
expect.objectContaining({
path: {},
value: {},
sort: {}
})
)
expect(ex).toBe('invalid path')
done()
})
Expand All @@ -469,21 +476,26 @@ describe('Testing Peer', () => {
.connect()
.then(() => peer.fetch(new Fetcher().path('startsWith', 'a')))
.then(() => {
expect(sendSpy).toBeCalledWith('fetch', {
id: '___f___1',
path: { startsWith: 'a' },
value: {},
sort: {}
})
expect(sendSpy).toBeCalledWith(
'fetch',
expect.objectContaining({
path: { startsWith: 'a' },
value: {},
sort: {}
})
)
})
.then(() => peer.fetch(new Fetcher().path('equals', 'b')))
.then(() => {
expect(sendSpy).toBeCalledWith('fetch', {
id: '___f___2',
path: { equals: 'b' },
value: {},
sort: {}
})
expect(sendSpy).toBeCalledWith(
'fetch',
expect.objectContaining({
path: { equals: 'b' },
value: {},
sort: {}
})
)

done()
})
})
Expand Down Expand Up @@ -549,7 +561,7 @@ describe('Testing Peer', () => {
.then(() => peer.fetch(fetcher))
.then(() => peer.unfetch(fetcher))
.then(() => {
expect(sendSpy).toBeCalledWith('unfetch', { id: '___f___1' })
expect(sendSpy).toBeCalledWith('unfetch', expect.anything())
done()
})
})
Expand Down

0 comments on commit 00409d7

Please sign in to comment.