-
-
Notifications
You must be signed in to change notification settings - Fork 217
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge remote-tracking branch 'origin/master' into 9586-implement-free…
…text-search-in-cht-datasource
- Loading branch information
Showing
103 changed files
with
2,657 additions
and
1,813 deletions.
There are no files selected for viewing
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
const { AsyncLocalStorage } = require('node:async_hooks'); | ||
const asyncLocalStorage = new AsyncLocalStorage(); | ||
const { REQUEST_ID_HEADER } = require('../server-utils'); | ||
|
||
const request = require('@medic/couch-request'); | ||
|
||
module.exports = { | ||
set: (req, callback) => { | ||
asyncLocalStorage.run({ clientRequest: req }, callback); | ||
}, | ||
getRequestId: () => { | ||
const localStorage = asyncLocalStorage.getStore(); | ||
return localStorage?.clientRequest?.id; | ||
}, | ||
}; | ||
|
||
request.initialize(module.exports, REQUEST_ID_HEADER); |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,62 @@ | ||
const sinon = require('sinon'); | ||
const rewire = require('rewire'); | ||
const { expect } = require('chai'); | ||
const request = require('@medic/couch-request'); | ||
const serverUtils = require('../../../src/server-utils'); | ||
|
||
describe('async-storage', () => { | ||
let service; | ||
|
||
beforeEach(() => { | ||
sinon.stub(request, 'initialize'); | ||
}); | ||
|
||
afterEach(() => { | ||
sinon.restore(); | ||
}); | ||
|
||
it('should initialize async storage and initialize couch-request', async () => { | ||
service = rewire('../../../src/services/async-storage'); | ||
expect(request.initialize.args).to.deep.equal([[ | ||
service, | ||
serverUtils.REQUEST_ID_HEADER | ||
]]); | ||
}); | ||
|
||
it('set should set request uuid', () => { | ||
service = rewire('../../../src/services/async-storage'); | ||
const asyncLocalStorage = service.__get__('asyncLocalStorage'); | ||
sinon.stub(asyncLocalStorage, 'run'); | ||
|
||
const req = { this: 'is a req' }; | ||
const cb = sinon.stub(); | ||
Object.freeze(req); | ||
service.set(req, cb); | ||
expect(asyncLocalStorage.run.args).to.deep.equal([[ | ||
{ clientRequest: req }, | ||
cb | ||
]]); | ||
}); | ||
|
||
it('getRequestId should return request id when set', done => { | ||
service = rewire('../../../src/services/async-storage'); | ||
const req = { id: 'uuid' }; | ||
service.set(req, () => { | ||
expect(service.getRequestId()).to.equal('uuid'); | ||
done(); | ||
}); | ||
}); | ||
|
||
it('getRequestId should return nothing when there is no local storage', () => { | ||
service = rewire('../../../src/services/async-storage'); | ||
expect(service.getRequestId()).to.equal(undefined); | ||
}); | ||
|
||
it('getRequestId should return nothing when there is no client request', done => { | ||
service = rewire('../../../src/services/async-storage'); | ||
service.set(undefined, () => { | ||
expect(service.getRequestId()).to.equal(undefined); | ||
done(); | ||
}); | ||
}); | ||
}); |
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
Oops, something went wrong.