Skip to content

Commit

Permalink
refactor(tagging): change sessionId creation logic from nanoId to UUID (
Browse files Browse the repository at this point in the history
  • Loading branch information
lauramargar authored Jan 30, 2024
1 parent acf1eb3 commit be06367
Show file tree
Hide file tree
Showing 5 changed files with 3,039 additions and 8,133 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,16 @@ describe('testing tagging module actions', () => {
localVue.config.productionTip = false; // Silent production console messages.
localVue.use(Vuex);

const selfSpy = jest.spyOn(self, 'self', 'get') as jest.SpyInstance<{
crypto: { randomUUID: () => string };
}>;

selfSpy.mockImplementation(() => ({
crypto: {
randomUUID: () => Math.floor(Math.random() * 1000000000).toString()
}
}));

const store: SafeStore<TaggingState, TaggingGetters, TaggingMutations, TaggingActions> =
new Store(taggingXStoreModule as any);
installNewXPlugin({ adapter, store }, localVue);
Expand Down
1 change: 0 additions & 1 deletion packages/x-utils/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,6 @@
},
"dependencies": {
"@empathyco/x-storage-service": "^2.0.3-alpha.0",
"nanoid": "~3.3.0",
"tslib": "~2.6.0"
},
"devDependencies": {
Expand Down
10 changes: 10 additions & 0 deletions packages/x-utils/src/services/__tests__/session.service.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,16 @@ describe('testing session id service', () => {
const sessionService = new DefaultSessionService(mockedStorageService, 1);
const storageKey = DefaultSessionService.SESSION_ID_KEY;

const selfSpy = jest.spyOn(self, 'self', 'get') as jest.SpyInstance<{
crypto: { randomUUID: () => string };
}>;

selfSpy.mockImplementation(() => ({
crypto: {
randomUUID: () => Math.floor(Math.random() * 1000000000).toString()
}
}));

const getItemSpy = jest.spyOn(mockedStorageService, 'getItem');
const setItemSpy = jest.spyOn(mockedStorageService, 'setItem');
const removeItemSpy = jest.spyOn(mockedStorageService, 'removeItem');
Expand Down
4 changes: 2 additions & 2 deletions packages/x-utils/src/services/session.service.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import { nanoid } from 'nanoid';
import {
BrowserStorageService,
InMemoryStorageService,
Expand Down Expand Up @@ -39,7 +38,8 @@ export class DefaultSessionService implements SessionService {
* @public
*/
getSessionId(): string {
const sessionId = this.storageService.getItem(DefaultSessionService.SESSION_ID_KEY) ?? nanoid();
const sessionId =
this.storageService.getItem(DefaultSessionService.SESSION_ID_KEY) ?? self.crypto.randomUUID();
this.storageService.setItem(DefaultSessionService.SESSION_ID_KEY, sessionId, this.ttlMs);
return sessionId;
}
Expand Down
Loading

0 comments on commit be06367

Please sign in to comment.