Fix tests (#438)

This commit is contained in:
Lukasz Ostrowski 2023-05-04 09:54:27 +02:00 committed by GitHub
parent 40bed99316
commit b56894fa14
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
4 changed files with 59 additions and 50 deletions

View file

@ -7,3 +7,4 @@ APL=
REST_APL_ENDPOINT= REST_APL_ENDPOINT=
REST_APL_TOKEN= REST_APL_TOKEN=
APP_DEBUG=debug # Pino logger levels

View file

@ -11,11 +11,10 @@ type WebhookContext = Parameters<NextWebhookApiHandler>["2"];
const mockedContext: Pick<WebhookContext, "authData"> = { const mockedContext: Pick<WebhookContext, "authData"> = {
authData: { authData: {
saleorApiUrl: "url", saleorApiUrl: "https://domain.saleor.io/graphql/",
token: "token", token: "token",
appId: "appId", appId: "appId",
domain: "domain", domain: "domain.saleor.io",
jwks: "jwks",
}, },
}; };
@ -68,7 +67,7 @@ describe("CMS Clients Operations", () => {
"first-provider": { "first-provider": {
name: "First provider", name: "First provider",
token: "token", token: "token",
baseUrl: "baseUrl", baseUrl: "http://localhost:3000",
contentTypeId: "contentTypeId", contentTypeId: "contentTypeId",
id: "first-provider", id: "first-provider",
providerName: "strapi", providerName: "strapi",
@ -76,7 +75,7 @@ describe("CMS Clients Operations", () => {
"second-provider": { "second-provider": {
name: "Second provider", name: "Second provider",
token: "token", token: "token",
baseUrl: "baseUrl", baseUrl: "http://localhost:3000",
contentTypeId: "contentTypeId", contentTypeId: "contentTypeId",
id: "second-provider", id: "second-provider",
providerName: "strapi", providerName: "strapi",
@ -84,7 +83,7 @@ describe("CMS Clients Operations", () => {
"third-provider": { "third-provider": {
name: "Third provider", name: "Third provider",
token: "token", token: "token",
baseUrl: "baseUrl", baseUrl: "http://localhost:3000",
contentTypeId: "contentTypeId", contentTypeId: "contentTypeId",
id: "third-provider", id: "third-provider",
providerName: "strapi", providerName: "strapi",
@ -108,17 +107,18 @@ describe("CMS Clients Operations", () => {
productVariantCmsKeys: [], productVariantCmsKeys: [],
}); });
expect(cmsOperations).toEqual<CmsClientOperations[]>([ const operationsItem = cmsOperations[0];
{
cmsProviderInstanceId: "first-provider", /**
operationType: "createProduct", * Replace deep equal with single ones due to some strange errors in vite/jest.
operations: { * Functions were not matched properly in deep object
createProduct: expect.any(Function), */
deleteProduct: expect.any(Function), expect(operationsItem.cmsProviderInstanceId).toBe("first-provider");
updateProduct: expect.any(Function), expect(operationsItem.operationType).toBe("createProduct");
}, expect(operationsItem.operations.createProduct).toEqual(expect.any(Function));
}, expect(operationsItem.operations.deleteProduct).toEqual(expect.any(Function));
]); expect(operationsItem.operations.updateProduct).toEqual(expect.any(Function));
expect(operationsItem.operations.ping).toEqual(expect.any(Function));
}); });
it("should return update operation when variant with channel listing that exists in provider instance passed", async () => { it("should return update operation when variant with channel listing that exists in provider instance passed", async () => {
@ -141,7 +141,7 @@ describe("CMS Clients Operations", () => {
"first-provider": { "first-provider": {
name: "First provider", name: "First provider",
token: "token", token: "token",
baseUrl: "baseUrl", baseUrl: "http://localhost:3000",
contentTypeId: "contentTypeId", contentTypeId: "contentTypeId",
id: "first-provider", id: "first-provider",
providerName: "strapi", providerName: "strapi",
@ -149,7 +149,7 @@ describe("CMS Clients Operations", () => {
"second-provider": { "second-provider": {
name: "Second provider", name: "Second provider",
token: "token", token: "token",
baseUrl: "baseUrl", baseUrl: "http://localhost:3000",
contentTypeId: "contentTypeId", contentTypeId: "contentTypeId",
id: "second-provider", id: "second-provider",
providerName: "strapi", providerName: "strapi",
@ -157,7 +157,7 @@ describe("CMS Clients Operations", () => {
"third-provider": { "third-provider": {
name: "Third provider", name: "Third provider",
token: "token", token: "token",
baseUrl: "baseUrl", baseUrl: "http://localhost:3000",
contentTypeId: "contentTypeId", contentTypeId: "contentTypeId",
id: "third-provider", id: "third-provider",
providerName: "strapi", providerName: "strapi",
@ -181,17 +181,18 @@ describe("CMS Clients Operations", () => {
productVariantCmsKeys: [createCmsKeyForSaleorItem("first-provider")], productVariantCmsKeys: [createCmsKeyForSaleorItem("first-provider")],
}); });
expect(cmsOperations).toEqual<CmsClientOperations[]>([ const operationsItem = cmsOperations[0];
{
cmsProviderInstanceId: "first-provider", /**
operationType: "updateProduct", * Replace deep equal with single ones due to some strange errors in vite/jest.
operations: { * Functions were not matched properly in deep object
createProduct: expect.any(Function), */
deleteProduct: expect.any(Function), expect(operationsItem.cmsProviderInstanceId).toBe("first-provider");
updateProduct: expect.any(Function), expect(operationsItem.operationType).toBe("updateProduct");
}, expect(operationsItem.operations.createProduct).toEqual(expect.any(Function));
}, expect(operationsItem.operations.deleteProduct).toEqual(expect.any(Function));
]); expect(operationsItem.operations.updateProduct).toEqual(expect.any(Function));
expect(operationsItem.operations.ping).toEqual(expect.any(Function));
}); });
it("should return delete operation when variant without channel listing that exists in provider instance passed", async () => { it("should return delete operation when variant without channel listing that exists in provider instance passed", async () => {
@ -214,7 +215,7 @@ describe("CMS Clients Operations", () => {
"first-provider": { "first-provider": {
name: "First provider", name: "First provider",
token: "token", token: "token",
baseUrl: "baseUrl", baseUrl: "http://localhost:3000",
contentTypeId: "contentTypeId", contentTypeId: "contentTypeId",
id: "first-provider", id: "first-provider",
providerName: "strapi", providerName: "strapi",
@ -222,7 +223,7 @@ describe("CMS Clients Operations", () => {
"second-provider": { "second-provider": {
name: "Second provider", name: "Second provider",
token: "token", token: "token",
baseUrl: "baseUrl", baseUrl: "http://localhost:3000",
contentTypeId: "contentTypeId", contentTypeId: "contentTypeId",
id: "second-provider", id: "second-provider",
providerName: "strapi", providerName: "strapi",
@ -230,7 +231,7 @@ describe("CMS Clients Operations", () => {
"third-provider": { "third-provider": {
name: "Third provider", name: "Third provider",
token: "token", token: "token",
baseUrl: "baseUrl", baseUrl: "http://localhost:3000",
contentTypeId: "contentTypeId", contentTypeId: "contentTypeId",
id: "third-provider", id: "third-provider",
providerName: "strapi", providerName: "strapi",
@ -254,16 +255,17 @@ describe("CMS Clients Operations", () => {
productVariantCmsKeys: [createCmsKeyForSaleorItem("first-provider")], productVariantCmsKeys: [createCmsKeyForSaleorItem("first-provider")],
}); });
expect(cmsOperations).toEqual<CmsClientOperations[]>([ const operationsItem = cmsOperations[0];
{
cmsProviderInstanceId: "first-provider", /**
operationType: "deleteProduct", * Replace deep equal with single ones due to some strange errors in vite/jest.
operations: { * Functions were not matched properly in deep object
createProduct: expect.any(Function), */
deleteProduct: expect.any(Function), expect(operationsItem.cmsProviderInstanceId).toBe("first-provider");
updateProduct: expect.any(Function), expect(operationsItem.operationType).toBe("deleteProduct");
}, expect(operationsItem.operations.createProduct).toEqual(expect.any(Function));
}, expect(operationsItem.operations.deleteProduct).toEqual(expect.any(Function));
]); expect(operationsItem.operations.updateProduct).toEqual(expect.any(Function));
expect(operationsItem.operations.ping).toEqual(expect.any(Function));
}); });
}); });

View file

@ -38,6 +38,8 @@ export const createCmsOperations = async ({
getProviderInstancesSettings(settingsManager), getProviderInstancesSettings(settingsManager),
]); ]);
logger.debug({ channelsSettingsParsed, providerInstancesSettingsParsed }, "Fetched settings");
const productVariantCmsProviderInstances = productVariantCmsKeys.map((cmsKey) => const productVariantCmsProviderInstances = productVariantCmsKeys.map((cmsKey) =>
getCmsIdFromSaleorItemKey(cmsKey) getCmsIdFromSaleorItemKey(cmsKey)
); );
@ -54,8 +56,10 @@ export const createCmsOperations = async ({
]; ];
if (!allProductVariantProviderInstancesToAlter.length) { if (!allProductVariantProviderInstancesToAlter.length) {
// todo: use instead: throw new Error("The channel settings were not found."); /*
// continue with other provider instances * todo: use instead: throw new Error("The channel settings were not found.");
* continue with other provider instances
*/
return []; return [];
} }
@ -75,8 +79,10 @@ export const createCmsOperations = async ({
); );
if (!validation.success) { if (!validation.success) {
// todo: use instead: throw new Error(validation.error.message); /*
// continue with other provider instances * todo: use instead: throw new Error(validation.error.message);
* continue with other provider instances
*/
logger.error("The provider instance settings validation failed.", { logger.error("The provider instance settings validation failed.", {
error: validation.error.message, error: validation.error.message,
}); });

View file

@ -4,7 +4,7 @@ import pino from "pino";
* TODO Set up log drain etc * TODO Set up log drain etc
*/ */
export const logger = pino({ export const logger = pino({
level: "debug", level: process.env.APP_DEBUG ?? "silent",
transport: transport:
process.env.NODE_ENV === "development" process.env.NODE_ENV === "development"
? { ? {