import cookie from 'js-cookie' import { Analytics } from '../../../core/analytics' import { SegmentioSettings } from '../../segmentio' import { ddAnonymizeContextPlugin } from '..' describe('Anonymous Context Plugin', () => { let analytics: Analytics let settings: SegmentioSettings beforeEach(async () => { jest.resetAllMocks() jest.restoreAllMocks() settings = { apiKey: 'foo' } analytics = new Analytics({ writeKey: settings.apiKey, }) await analytics.register(ddAnonymizeContextPlugin()) }) afterEach(() => { analytics.reset() Object.keys(cookie.get()).map((k) => cookie.remove(k)) window.localStorage.clear() }) it('should fields from group calls', async () => { const context = await analytics.group('Group1') const eventContext = context.event.context! expect(eventContext.locale).toBeFalsy() expect(eventContext.timezone).toBeFalsy() expect(eventContext.userAgent).toBeFalsy() }) it('should remove fields from identify calls', async () => { const context = await analytics.identify('User1') const eventContext = context.event.context! expect(eventContext.locale).toBeFalsy() expect(eventContext.timezone).toBeFalsy() expect(eventContext.userAgent).toBeFalsy() }) it('should remove fields from track calls', async () => { const context = await analytics.track('My Event') const eventContext = context.event.context! expect(eventContext.locale).toBeFalsy() expect(eventContext.timezone).toBeFalsy() expect(eventContext.userAgent).toBeFalsy() }) })