Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add integration tests. #154

Merged
merged 1 commit into from
Jan 9, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 @@ -29,6 +29,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 @@ -39,6 +45,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: ResolvedConfig): 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: ResolvedConfig, id: string): Promise<TokenizeResponse>
});
}

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: ResolvedConfig, id: string): Promise<Uid2TokenRespons

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

This file was deleted.

Loading