feat: track Memind product analytics
This commit is contained in:
@@ -57,6 +57,8 @@ function createMiddleware(overrides = {}) {
|
||||
return createPortalApiAuthMiddleware({
|
||||
isPageDataPublicPath,
|
||||
isLegacyPageDataApiPath,
|
||||
isProductAnalyticsPublicPath: (path, method) =>
|
||||
method === 'GET' && path === '/analytics/context',
|
||||
logger: createLogger(),
|
||||
...overrides,
|
||||
});
|
||||
@@ -143,6 +145,36 @@ test('multi-user public routes preserve optional user hydration', async () => {
|
||||
assert.equal(getMeCalls, 1);
|
||||
});
|
||||
|
||||
test('product analytics context preserves optional user hydration', async () => {
|
||||
let getMeCalls = 0;
|
||||
const user = { id: 'analytics-user' };
|
||||
const middleware = createMiddleware({
|
||||
getUserAuth: () => ({
|
||||
async getMe(token) {
|
||||
getMeCalls += 1;
|
||||
assert.equal(token, 'user-token');
|
||||
return user;
|
||||
},
|
||||
}),
|
||||
getTkmindProxy: () => ({}),
|
||||
});
|
||||
|
||||
const anonymous = await invoke(middleware, {
|
||||
path: '/analytics/context',
|
||||
userSession: null,
|
||||
});
|
||||
assert.equal(anonymous.nextCalls, 1);
|
||||
assert.equal(anonymous.req.currentUser, undefined);
|
||||
|
||||
const authenticated = await invoke(middleware, {
|
||||
path: '/analytics/context',
|
||||
userSession: { id: 'session-analytics' },
|
||||
});
|
||||
assert.equal(authenticated.nextCalls, 1);
|
||||
assert.equal(authenticated.req.currentUser, user);
|
||||
assert.equal(getMeCalls, 1);
|
||||
});
|
||||
|
||||
test('multi-user private routes preserve login, expiry, and double-check behavior', async () => {
|
||||
let currentUser = { id: 'user-1' };
|
||||
let getMeCalls = 0;
|
||||
|
||||
Reference in New Issue
Block a user