Skip to content

Commit d2d2d57

Browse files
authored
Merge pull request #18 from leapfrogtechnology/test-get-id
Add test cases for getId() method
2 parents 3a4f124 + 0b2e0cd commit d2d2d57

File tree

2 files changed

+36
-5
lines changed

2 files changed

+36
-5
lines changed

README.md

Lines changed: 15 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -114,16 +114,16 @@ app.listen(port, () => console.log(`Example app listening on port ${port}!`));
114114

115115
Initialize the async store based on the adapter provided.
116116

117-
- `@param {AsyncStoreAdapter} [adapter=AsyncStoreAdapter.DOMAIN]` - Async store adapter to use.
118-
- `@returns {(params: AsyncStoreParams) => void}` - Returns a function that takes a callback which will be triggered once the store has been initialized.
117+
- `@param {AsyncStoreAdapter} [adapter=AsyncStoreAdapter.DOMAIN]` - Async store adapter to use.
118+
- `@returns {(params: AsyncStoreParams) => void}` - Returns a function that takes a callback which will be triggered once the store has been initialized.
119119

120120
```js
121121
const store = require('@leapfrogtechnology/async-store');
122122

123123
store.initialize()(callback);
124124

125125
function callback() {
126-
// Do something with the store.
126+
// Do something with the store.
127127
}
128128
```
129129

@@ -157,7 +157,7 @@ store.set({ foo: 'Hello', bar: 'World' });
157157

158158
Gets a value by a key from the store.
159159

160-
- `@params {string} key` - Key to get from the store.
160+
- `@params {string} key` - Key to get from the store.
161161
- `@returns {any}` - Returns the value persisted in the store by `key` which could be `null` if key not found. Any error caught during the retrieval will be thrown and cascaded.
162162

163163
```js
@@ -168,13 +168,23 @@ const foo = store.get('foo');
168168

169169
Gets a value by a key from the store. If anything fails, it returns `null` without emitting error event.
170170

171-
- `@params {string} key` - Key to get from the store.
171+
- `@params {string} key` - Key to get from the store.
172172
- `@returns {any}` - Returns the value persisted in the store by `key` which could be `null` if key not found. Any error caught during the retrieval will be supressed and `null` value is returned.
173173

174174
```js
175175
const foo = store.find('foo');
176176
```
177177

178+
### getId()
179+
180+
Gets the unique domain id created for the current context/scope.
181+
182+
- `@returns {string | undefined}` - Returns the unique domain id.
183+
184+
```js
185+
const requestIdentifier = store.getId();
186+
```
187+
178188
## Changelog
179189

180190
Check the [CHANGELOG](CHANGELOG.md) for release history.

test/domain.test.ts

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,27 @@ describe('store: [adapter=DOMAIN]', () => {
5454
});
5555
});
5656

57+
describe('getId()', () => {
58+
it('should return unique value if store is initialized', done => {
59+
const callback = () => {
60+
expect(globalStore.getId()).to.be.an('string');
61+
expect(globalStore.getId()).to.not.equal(null);
62+
expect(globalStore.getId()).to.not.equal(undefined);
63+
64+
done();
65+
};
66+
67+
globalStore.initialize(adapter)(callback);
68+
});
69+
70+
it('should return `undefined` if store is not initialized.', done => {
71+
expect(globalStore.getId).to.not.throw();
72+
expect(globalStore.getId()).to.equal(undefined);
73+
74+
done();
75+
});
76+
});
77+
5778
describe('find()', () => {
5879
it('should successfully return value in synchronous callback', done => {
5980
const callback = () => {

0 commit comments

Comments
 (0)