Skip to content
This repository has been archived by the owner on Feb 22, 2023. It is now read-only.

Commit

Permalink
Remove usage session ID cookie and use ephemeral Vuex data
Browse files Browse the repository at this point in the history
  • Loading branch information
sarayourfriend committed Feb 3, 2022
1 parent e603ec3 commit 8211525
Show file tree
Hide file tree
Showing 6 changed files with 51 additions and 49 deletions.
1 change: 1 addition & 0 deletions package.json
Expand Up @@ -92,6 +92,7 @@
"@testing-library/user-event": "^13.2.1",
"@testing-library/vue": "^5.8.2",
"@types/jest": "^26.0.22",
"@types/uuid": "^8.3.4",
"@vue/test-utils": "^1.1.3",
"autoprefixer": "^10.4.0",
"babel-jest": "^26.6.3",
Expand Down
6 changes: 6 additions & 0 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

18 changes: 15 additions & 3 deletions src/store/user.js
@@ -1,6 +1,18 @@
import SessionId from '~/utils/session-id'
import { v4 as uuidv4 } from 'uuid'

/**
* @typedef UserState
* @property {string | undefined} usageSessionId
*/

/**
* @returns {UserState}
*/
export const state = () => ({
abSessionId: SessionId('abSessionId', true),
usageSessionId: SessionId('usageSessionId'),
/**
* Default to `undefined` on the client and let client side
* SSR state hydration pull the SSR generated ID into the client.
* This way we avoid generating any spurious IDs on the client.
*/
usageSessionId: process.server ? uuidv4() : undefined,
})
46 changes: 0 additions & 46 deletions src/utils/session-id.js

This file was deleted.

28 changes: 28 additions & 0 deletions test/unit/specs/store/user.spec.js
@@ -0,0 +1,28 @@
import * as user from '~/store/user'
import { v4 as uuidv4 } from 'uuid'

jest.mock('uuid', () => ({ v4: jest.fn() }))

describe('user store', () => {
beforeEach(() => {
process.server = false
process.client = false
})

afterAll(() => {
// avoid polluting other tests that might be affected by these flags
delete process.server
delete process.client
})

it('should generate a new usageSessionId when on server', () => {
uuidv4.mockReturnValue('abcd-1234')
process.server = true
expect(user.state().usageSessionId).toEqual('abcd-1234')
})

it('should not generate a new usageSessionId when on client', () => {
process.client = true
expect(user.state().usageSessionId).toBeUndefined()
})
})
1 change: 1 addition & 0 deletions tsconfig.json
Expand Up @@ -37,6 +37,7 @@
"src/composables/use-active-audio.js",
"src/data/api-service.js",
"src/data/usage-data-service.js",
"src/store/user.js",
"src/utils/warn.js"
]
}

0 comments on commit 8211525

Please sign in to comment.