From c5b80a19894c80ca80c660e39b112faaca645a37 Mon Sep 17 00:00:00 2001 From: Ural Date: Wed, 10 Apr 2024 16:13:00 +0200 Subject: [PATCH] feat(add-consent): add missing tests for consent --- src/consent/get-all-checkboxes.spec.ts | 33 +++++++++++++++++++++++ src/consent/get-all.spec.ts | 33 +++++++++++++++++++++++ src/consent/get-purposes.spec.ts | 36 +++++++++++++++++++++++++ src/consent/get.spec.ts | 34 +++++++++++++++++++++++ src/consent/send-queued-event.spec.ts | 33 +++++++++++++++++++++++ src/consent/set-all-checkboxes.spect.ts | 33 +++++++++++++++++++++++ src/consent/set-all.spec.ts | 33 +++++++++++++++++++++++ src/consent/set-checkboxes.spec.ts | 34 +++++++++++++++++++++++ src/consent/set.spec.ts | 34 +++++++++++++++++++++++ 9 files changed, 303 insertions(+) create mode 100644 src/consent/get-all-checkboxes.spec.ts create mode 100644 src/consent/get-all.spec.ts create mode 100644 src/consent/get-purposes.spec.ts create mode 100644 src/consent/get.spec.ts create mode 100644 src/consent/send-queued-event.spec.ts create mode 100644 src/consent/set-all-checkboxes.spect.ts create mode 100644 src/consent/set-all.spec.ts create mode 100644 src/consent/set-checkboxes.spec.ts create mode 100644 src/consent/set.spec.ts diff --git a/src/consent/get-all-checkboxes.spec.ts b/src/consent/get-all-checkboxes.spec.ts new file mode 100644 index 0000000..95616b0 --- /dev/null +++ b/src/consent/get-all-checkboxes.spec.ts @@ -0,0 +1,33 @@ +import { getAllCheckboxes } from './get-all-checkboxes'; + +declare global { + interface Window { + // eslint-disable-next-line @typescript-eslint/no-explicit-any + zaraz: any; + } +} + +let windowObj: Window & typeof globalThis; + +beforeAll(() => { + windowObj = window; +}); + +afterAll(() => { + window = windowObj; +}); + +describe('getAllCheckboxes()', () => { + it('should return all checkboxes from zaraz consent', () => { + const checkboxesMock = { key1: true, key2: false }; + window.zaraz = { + consent: { + getAllCheckboxes: jest.fn().mockReturnValue(checkboxesMock), + }, + }; + + const checkboxes = getAllCheckboxes(); + + expect(checkboxes).toEqual(checkboxesMock); + }); +}); diff --git a/src/consent/get-all.spec.ts b/src/consent/get-all.spec.ts new file mode 100644 index 0000000..e808f99 --- /dev/null +++ b/src/consent/get-all.spec.ts @@ -0,0 +1,33 @@ +import { getAll } from './get-all'; + +declare global { + interface Window { + // eslint-disable-next-line @typescript-eslint/no-explicit-any + zaraz: any; + } +} + +let windowObj: Window & typeof globalThis; + +beforeAll(() => { + windowObj = window; +}); + +afterAll(() => { + window = windowObj; +}); + +describe('getAll()', () => { + it('should return all consents from zaraz consent', () => { + const consentsMock = { key1: true, key2: false }; + window.zaraz = { + consent: { + getAll: jest.fn().mockReturnValue(consentsMock), + }, + }; + + const consents = getAll(); + + expect(consents).toEqual(consentsMock); + }); +}); diff --git a/src/consent/get-purposes.spec.ts b/src/consent/get-purposes.spec.ts new file mode 100644 index 0000000..63de7a4 --- /dev/null +++ b/src/consent/get-purposes.spec.ts @@ -0,0 +1,36 @@ +import { getPurposes } from './get-purposes'; + +declare global { + interface Window { + // eslint-disable-next-line @typescript-eslint/no-explicit-any + zaraz: any; + } +} + +let windowObj: Window & typeof globalThis; + +beforeAll(() => { + windowObj = window; +}); + +afterAll(() => { + window = windowObj; +}); + +describe('getPurposes()', () => { + it('should return all purposes from zaraz consent', () => { + const purposesMock = { + key1: { name: 'Name 1', description: 'Description 1', order: 1 }, + key2: { name: 'Name 2', description: 'Description 2', order: 2 }, + }; + window.zaraz = { + consent: { + purposes: purposesMock, + }, + }; + + const purposes = getPurposes(); + + expect(purposes).toEqual(purposesMock); + }); +}); diff --git a/src/consent/get.spec.ts b/src/consent/get.spec.ts new file mode 100644 index 0000000..db1b3cc --- /dev/null +++ b/src/consent/get.spec.ts @@ -0,0 +1,34 @@ +import { get } from './get'; + +declare global { + interface Window { + // eslint-disable-next-line @typescript-eslint/no-explicit-any + zaraz: any; + } +} + +let windowObj: Window & typeof globalThis; + +beforeAll(() => { + windowObj = window; +}); + +afterAll(() => { + window = windowObj; +}); + +describe('get()', () => { + it('should return the consent status for a purpose from zaraz consent', () => { + const getMock = jest.fn().mockReturnValue(true); + window.zaraz = { + consent: { + get: getMock, + }, + }; + + const consentStatus = get('key'); + + expect(consentStatus).toBe(true); + expect(getMock).toHaveBeenCalledWith('key'); + }); +}); diff --git a/src/consent/send-queued-event.spec.ts b/src/consent/send-queued-event.spec.ts new file mode 100644 index 0000000..12c6656 --- /dev/null +++ b/src/consent/send-queued-event.spec.ts @@ -0,0 +1,33 @@ +import { sendQueuedEvents } from './send-queued-events'; + +declare global { + interface Window { + // eslint-disable-next-line @typescript-eslint/no-explicit-any + zaraz: any; + } +} + +let windowObj: Window & typeof globalThis; + +beforeAll(() => { + windowObj = window; +}); + +afterAll(() => { + window = windowObj; +}); + +describe('sendQueuedEvents()', () => { + it('should call sendQueuedEvents method on zaraz consent', () => { + const sendQueuedEventsMock = jest.fn(); + window.zaraz = { + consent: { + sendQueuedEvents: sendQueuedEventsMock, + }, + }; + + sendQueuedEvents(); + + expect(sendQueuedEventsMock).toHaveBeenCalled(); + }); +}); diff --git a/src/consent/set-all-checkboxes.spect.ts b/src/consent/set-all-checkboxes.spect.ts new file mode 100644 index 0000000..29c3acc --- /dev/null +++ b/src/consent/set-all-checkboxes.spect.ts @@ -0,0 +1,33 @@ +import { setAllCheckboxes } from './set-all-checkboxes'; + +declare global { + interface Window { + // eslint-disable-next-line @typescript-eslint/no-explicit-any + zaraz: any; + } +} + +let windowObj: Window & typeof globalThis; + +beforeAll(() => { + windowObj = window; +}); + +afterAll(() => { + window = windowObj; +}); + +describe('setAllCheckboxes()', () => { + it('should call setAllCheckboxes method on zaraz consent with the correct argument', () => { + const setAllCheckboxesMock = jest.fn(); + window.zaraz = { + consent: { + setAllCheckboxes: setAllCheckboxesMock, + }, + }; + + setAllCheckboxes(true); + + expect(setAllCheckboxesMock).toHaveBeenCalledWith(true); + }); +}); diff --git a/src/consent/set-all.spec.ts b/src/consent/set-all.spec.ts new file mode 100644 index 0000000..35e086b --- /dev/null +++ b/src/consent/set-all.spec.ts @@ -0,0 +1,33 @@ +import { setAll } from './set-all'; + +declare global { + interface Window { + // eslint-disable-next-line @typescript-eslint/no-explicit-any + zaraz: any; + } +} + +let windowObj: Window & typeof globalThis; + +beforeAll(() => { + windowObj = window; +}); + +afterAll(() => { + window = windowObj; +}); + +describe('setAll()', () => { + it('should call setAll method on zaraz consent with the correct argument', () => { + const setAllMock = jest.fn(); + window.zaraz = { + consent: { + setAll: setAllMock, + }, + }; + + setAll(true); + + expect(setAllMock).toHaveBeenCalledWith(true); + }); +}); diff --git a/src/consent/set-checkboxes.spec.ts b/src/consent/set-checkboxes.spec.ts new file mode 100644 index 0000000..f02f2ca --- /dev/null +++ b/src/consent/set-checkboxes.spec.ts @@ -0,0 +1,34 @@ +import { setCheckboxes } from './set-checkboxes'; + +declare global { + interface Window { + // eslint-disable-next-line @typescript-eslint/no-explicit-any + zaraz: any; + } +} + +let windowObj: Window & typeof globalThis; + +beforeAll(() => { + windowObj = window; +}); + +afterAll(() => { + window = windowObj; +}); + +describe('setCheckboxes()', () => { + it('should call setCheckboxes method on zaraz consent with the correct argument', () => { + const setCheckboxesMock = jest.fn(); + window.zaraz = { + consent: { + setCheckboxes: setCheckboxesMock, + }, + }; + + const checkboxesStatus = { key1: true, key2: false }; + setCheckboxes(checkboxesStatus); + + expect(setCheckboxesMock).toHaveBeenCalledWith(checkboxesStatus); + }); +}); diff --git a/src/consent/set.spec.ts b/src/consent/set.spec.ts new file mode 100644 index 0000000..febc75f --- /dev/null +++ b/src/consent/set.spec.ts @@ -0,0 +1,34 @@ +import { set } from './set'; + +declare global { + interface Window { + // eslint-disable-next-line @typescript-eslint/no-explicit-any + zaraz: any; + } +} + +let windowObj: Window & typeof globalThis; + +beforeAll(() => { + windowObj = window; +}); + +afterAll(() => { + window = windowObj; +}); + +describe('set()', () => { + it('should call set method on zaraz consent with the correct argument', () => { + const setMock = jest.fn(); + window.zaraz = { + consent: { + set: setMock, + }, + }; + + const consentPreferences = { key1: true, key2: false }; + set(consentPreferences); + + expect(setMock).toHaveBeenCalledWith(consentPreferences); + }); +});