Skip to content

Commit

Permalink
Add integration tests.
Browse files Browse the repository at this point in the history
  • Loading branch information
dany-pellerin committed Dec 18, 2024
1 parent 1d70c16 commit fad2239
Show file tree
Hide file tree
Showing 21 changed files with 1,334 additions and 68 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
node_modules
coverage
lib/dist/
demos/react/dist
demos/npm/dist
Expand Down
8 changes: 7 additions & 1 deletion jest.config.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,13 @@
/** @type {import('jest').Config} */
const config = {
testEnvironment: "jsdom",
setupFiles: ["<rootDir>/setup-jest.js"],
resetMocks: false,
setupFiles: ["<rootDir>/setup-jest.js", "jest-localstorage-mock"],
setupFilesAfterEnv: ["<rootDir>/setup-env.js"],
testEnvironmentOptions: {
customExportConditions: [""],
},
collectCoverage: true,
};

module.exports = config;
3 changes: 2 additions & 1 deletion lib/addons/gpt.test.js
Original file line number Diff line number Diff line change
@@ -1,12 +1,13 @@
import OptableSDK from "../sdk";
import { TEST_HOST, TEST_SITE } from "../test/mocks.ts";
import "./gpt.ts";

describe("OptableSDK - installGPTSecureSignals", () => {
let SDK;

beforeEach(() => {
// Initialize the SDK instance
SDK = new OptableSDK({ host: "localhost", site: "test" });
SDK = new OptableSDK({ host: TEST_HOST, site: TEST_SITE });

// Reset global googletag object
window.googletag = { cmd: [], secureSignalProviders: [] };
Expand Down
3 changes: 2 additions & 1 deletion lib/addons/topics-api.test.js
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
import OptableSDK from "../sdk";
import { TEST_HOST, TEST_SITE } from "../test/mocks.ts";
import "./topics-api.ts";

describe("OptableSDK - ingestTopics", () => {
let SDK;

beforeEach(() => {
SDK = new OptableSDK({ host: "localhost", site: "test" });
SDK = new OptableSDK({ host: TEST_HOST, site: TEST_SITE });
// Mock the profile method
SDK.profile = jest.fn();
});
Expand Down
3 changes: 2 additions & 1 deletion lib/addons/try-identify.test.js
Original file line number Diff line number Diff line change
@@ -1,12 +1,13 @@
import OptableSDK from "../sdk";
import "./try-identify";
import { TEST_HOST, TEST_SITE } from "../test/mocks.ts";

describe("tryIdentifyFromParams", () => {
var SDK = null;

beforeEach(() => {
delete window.location;
SDK = new OptableSDK({ host: "localhost", site: "test" });
SDK = new OptableSDK({ host: TEST_HOST, site: TEST_SITE });
SDK.identify = jest.fn();
});

Expand Down
12 changes: 12 additions & 0 deletions lib/core/storage.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,12 @@ describe("LocalStorage", () => {
expect(store.getTargeting()).toBeNull();
});

test("allows to set targeting with empty value", () => {
const store = new LocalStorage(randomConfig());
expect(store.setTargeting());
expect(store.getTargeting()).toBeNull();
});

test("allows to store and retrieve a site config", () => {
const store = new LocalStorage(randomConfig());
expect(store.getSite()).toBeNull();
Expand All @@ -35,6 +41,12 @@ describe("LocalStorage", () => {
expect(store.getSite()).toBeNull();
});

test("allows to set site with empty value", () => {
const store = new LocalStorage(randomConfig());
expect(store.setSite());
expect(store.getSite()).toBeNull();
});

test("auto fixes v1 targeting as v2 base on audience key presence", () => {
const store = new LocalStorage(randomConfig());
window.localStorage.setItem(store.targetingV1Key, JSON.stringify({ k1: ["v1"], k2: ["v2"] }));
Expand Down
5 changes: 5 additions & 0 deletions lib/edge/passport.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
type EdgePassport = {
passport: string;
};

export type { EdgePassport };
4 changes: 3 additions & 1 deletion lib/edge/site.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ type AuctionConfig = {
type SiteResponse = {
interestGroupPixel: string;
auctionConfig?: AuctionConfig | null;
auctionConfigURL?: string;
getTopicsURL: string;
};

Expand All @@ -40,5 +41,6 @@ function SiteFromCache(config: Required<OptableConfig>): SiteResponse | null {
return ls.getSite();
}

export { Site, SiteResponse, SiteFromCache, Size, AuctionConfig };
export { Site, SiteFromCache };
export default Site;
export type { SiteResponse, Size, AuctionConfig };
3 changes: 2 additions & 1 deletion lib/edge/targeting.ts
Original file line number Diff line number Diff line change
Expand Up @@ -103,5 +103,6 @@ function TargetingKeyValues(tdata: TargetingResponse | null): TargetingKeyValues
return result;
}

export { Targeting, TargetingFromCache, TargetingClearCache, TargetingResponse, PrebidORTB2, TargetingKeyValues };
export { Targeting, TargetingFromCache, TargetingClearCache, PrebidORTB2, TargetingKeyValues };
export default Targeting;
export type { TargetingResponse };
3 changes: 2 additions & 1 deletion lib/edge/tokenize.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,5 +23,6 @@ function Tokenize(config: Required<OptableConfig>, id: string): Promise<Tokenize
});
}

export { Tokenize, TokenizeRequest, TokenizeResponse };
export { Tokenize };
export default Tokenize;
export type { TokenizeRequest, TokenizeResponse };
1 change: 1 addition & 0 deletions lib/edge/uid2_token.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,3 +22,4 @@ function Uid2Token(config: Required<OptableConfig>, id: string): Promise<Uid2Tok

export { Uid2Token };
export default Uid2Token;
export type { Uid2TokenResponse };
49 changes: 0 additions & 49 deletions lib/sdk.test.js

This file was deleted.

Loading

0 comments on commit fad2239

Please sign in to comment.