
* Change process-async-saleor-webhook to process-saleor-webhook and add better debug logs * Change processWebhook name * wip * Add base class structure * refactor * add sync payload builder * wip * wip * Add some missing webhook responses * Fix tests for Async version * Fix tests * Add MockAPL test util * Refactor tests to use MockAPL * Add test to sync webhook * Restore legacy subscriptionQueryAst field for compatibility * CR Fixes - TS type & event -> eventType * Changelog, docs and remove old payment webhooks * Apply suggestions from code review Co-authored-by: Krzysztof Wolski <krzysztof.k.wolski@gmail.com> * Update src/handlers/next/saleor-webhooks/process-saleor-webhook.ts Co-authored-by: Krzysztof Wolski <krzysztof.k.wolski@gmail.com> --------- Co-authored-by: Krzysztof Wolski <krzysztof.k.wolski@gmail.com>
70 lines
1.5 KiB
TypeScript
70 lines
1.5 KiB
TypeScript
import { vi } from "vitest";
|
|
|
|
import { APL, AuthData } from "../APL";
|
|
|
|
type Options = {
|
|
workForApiUrl?: string;
|
|
savedAllAuthData?: AuthData[];
|
|
};
|
|
|
|
/**
|
|
* Test utility used across scenarios to simulate various APL behaviors
|
|
*/
|
|
export class MockAPL implements APL {
|
|
private readonly options: Options = {
|
|
workForApiUrl: "https://example.com/graphql/",
|
|
savedAllAuthData: [],
|
|
};
|
|
|
|
constructor(opts?: Options) {
|
|
this.options = {
|
|
...this.options,
|
|
...(opts ?? {}),
|
|
};
|
|
|
|
this.workingSaleorApiUrl = this.options.workForApiUrl ?? this.workingSaleorApiUrl;
|
|
}
|
|
|
|
mockJwks = "{}";
|
|
|
|
mockToken = "mock-token";
|
|
|
|
mockAppId = "mock-app-id";
|
|
|
|
workingSaleorApiUrl = "https://example.com/graphql/";
|
|
|
|
resolveDomainFromApiUrl = (apiUrl: string) =>
|
|
apiUrl.replace("/graphql/", "").replace("https://", "");
|
|
|
|
get workingSaleorDomain() {
|
|
return this.resolveDomainFromApiUrl(this.workingSaleorApiUrl);
|
|
}
|
|
|
|
async get(saleorApiUrl: string) {
|
|
if (saleorApiUrl === this.workingSaleorApiUrl) {
|
|
return {
|
|
domain: this.resolveDomainFromApiUrl(saleorApiUrl),
|
|
token: this.mockToken,
|
|
saleorApiUrl,
|
|
appId: this.mockAppId,
|
|
jwks: this.mockJwks,
|
|
};
|
|
}
|
|
|
|
return undefined;
|
|
}
|
|
|
|
set = vi.fn();
|
|
|
|
delete = vi.fn();
|
|
|
|
getAll = vi.fn().mockImplementation(async () => this.options.savedAllAuthData);
|
|
|
|
isReady = vi.fn().mockImplementation(async () => ({
|
|
ready: true,
|
|
}));
|
|
|
|
isConfigured = vi.fn().mockImplementation(async () => ({
|
|
configured: true,
|
|
}));
|
|
}
|