diff --git a/apps/cms/.env.example b/apps/cms/.env.example index c923f4e..0dabf7d 100644 --- a/apps/cms/.env.example +++ b/apps/cms/.env.example @@ -7,3 +7,4 @@ APL= REST_APL_ENDPOINT= REST_APL_TOKEN= +APP_DEBUG=debug # Pino logger levels diff --git a/apps/cms/src/lib/cms/client/clients-operations.test.ts b/apps/cms/src/lib/cms/client/clients-operations.test.ts index 07d9b2e..f55a95f 100644 --- a/apps/cms/src/lib/cms/client/clients-operations.test.ts +++ b/apps/cms/src/lib/cms/client/clients-operations.test.ts @@ -11,11 +11,10 @@ type WebhookContext = Parameters["2"]; const mockedContext: Pick = { authData: { - saleorApiUrl: "url", + saleorApiUrl: "https://domain.saleor.io/graphql/", token: "token", appId: "appId", - domain: "domain", - jwks: "jwks", + domain: "domain.saleor.io", }, }; @@ -68,7 +67,7 @@ describe("CMS Clients Operations", () => { "first-provider": { name: "First provider", token: "token", - baseUrl: "baseUrl", + baseUrl: "http://localhost:3000", contentTypeId: "contentTypeId", id: "first-provider", providerName: "strapi", @@ -76,7 +75,7 @@ describe("CMS Clients Operations", () => { "second-provider": { name: "Second provider", token: "token", - baseUrl: "baseUrl", + baseUrl: "http://localhost:3000", contentTypeId: "contentTypeId", id: "second-provider", providerName: "strapi", @@ -84,7 +83,7 @@ describe("CMS Clients Operations", () => { "third-provider": { name: "Third provider", token: "token", - baseUrl: "baseUrl", + baseUrl: "http://localhost:3000", contentTypeId: "contentTypeId", id: "third-provider", providerName: "strapi", @@ -108,17 +107,18 @@ describe("CMS Clients Operations", () => { productVariantCmsKeys: [], }); - expect(cmsOperations).toEqual([ - { - cmsProviderInstanceId: "first-provider", - operationType: "createProduct", - operations: { - createProduct: expect.any(Function), - deleteProduct: expect.any(Function), - updateProduct: expect.any(Function), - }, - }, - ]); + const operationsItem = cmsOperations[0]; + + /** + * Replace deep equal with single ones due to some strange errors in vite/jest. + * Functions were not matched properly in deep object + */ + expect(operationsItem.cmsProviderInstanceId).toBe("first-provider"); + 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 () => { @@ -141,7 +141,7 @@ describe("CMS Clients Operations", () => { "first-provider": { name: "First provider", token: "token", - baseUrl: "baseUrl", + baseUrl: "http://localhost:3000", contentTypeId: "contentTypeId", id: "first-provider", providerName: "strapi", @@ -149,7 +149,7 @@ describe("CMS Clients Operations", () => { "second-provider": { name: "Second provider", token: "token", - baseUrl: "baseUrl", + baseUrl: "http://localhost:3000", contentTypeId: "contentTypeId", id: "second-provider", providerName: "strapi", @@ -157,7 +157,7 @@ describe("CMS Clients Operations", () => { "third-provider": { name: "Third provider", token: "token", - baseUrl: "baseUrl", + baseUrl: "http://localhost:3000", contentTypeId: "contentTypeId", id: "third-provider", providerName: "strapi", @@ -181,17 +181,18 @@ describe("CMS Clients Operations", () => { productVariantCmsKeys: [createCmsKeyForSaleorItem("first-provider")], }); - expect(cmsOperations).toEqual([ - { - cmsProviderInstanceId: "first-provider", - operationType: "updateProduct", - operations: { - createProduct: expect.any(Function), - deleteProduct: expect.any(Function), - updateProduct: expect.any(Function), - }, - }, - ]); + const operationsItem = cmsOperations[0]; + + /** + * Replace deep equal with single ones due to some strange errors in vite/jest. + * Functions were not matched properly in deep object + */ + expect(operationsItem.cmsProviderInstanceId).toBe("first-provider"); + 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 () => { @@ -214,7 +215,7 @@ describe("CMS Clients Operations", () => { "first-provider": { name: "First provider", token: "token", - baseUrl: "baseUrl", + baseUrl: "http://localhost:3000", contentTypeId: "contentTypeId", id: "first-provider", providerName: "strapi", @@ -222,7 +223,7 @@ describe("CMS Clients Operations", () => { "second-provider": { name: "Second provider", token: "token", - baseUrl: "baseUrl", + baseUrl: "http://localhost:3000", contentTypeId: "contentTypeId", id: "second-provider", providerName: "strapi", @@ -230,7 +231,7 @@ describe("CMS Clients Operations", () => { "third-provider": { name: "Third provider", token: "token", - baseUrl: "baseUrl", + baseUrl: "http://localhost:3000", contentTypeId: "contentTypeId", id: "third-provider", providerName: "strapi", @@ -254,16 +255,17 @@ describe("CMS Clients Operations", () => { productVariantCmsKeys: [createCmsKeyForSaleorItem("first-provider")], }); - expect(cmsOperations).toEqual([ - { - cmsProviderInstanceId: "first-provider", - operationType: "deleteProduct", - operations: { - createProduct: expect.any(Function), - deleteProduct: expect.any(Function), - updateProduct: expect.any(Function), - }, - }, - ]); + const operationsItem = cmsOperations[0]; + + /** + * Replace deep equal with single ones due to some strange errors in vite/jest. + * Functions were not matched properly in deep object + */ + expect(operationsItem.cmsProviderInstanceId).toBe("first-provider"); + 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)); }); }); diff --git a/apps/cms/src/lib/cms/client/clients-operations.ts b/apps/cms/src/lib/cms/client/clients-operations.ts index f784f99..1965468 100644 --- a/apps/cms/src/lib/cms/client/clients-operations.ts +++ b/apps/cms/src/lib/cms/client/clients-operations.ts @@ -38,6 +38,8 @@ export const createCmsOperations = async ({ getProviderInstancesSettings(settingsManager), ]); + logger.debug({ channelsSettingsParsed, providerInstancesSettingsParsed }, "Fetched settings"); + const productVariantCmsProviderInstances = productVariantCmsKeys.map((cmsKey) => getCmsIdFromSaleorItemKey(cmsKey) ); @@ -54,8 +56,10 @@ export const createCmsOperations = async ({ ]; 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 []; } @@ -75,8 +79,10 @@ export const createCmsOperations = async ({ ); 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.", { error: validation.error.message, }); diff --git a/apps/cms/src/lib/logger.ts b/apps/cms/src/lib/logger.ts index 314340a..4ad54f7 100644 --- a/apps/cms/src/lib/logger.ts +++ b/apps/cms/src/lib/logger.ts @@ -4,7 +4,7 @@ import pino from "pino"; * TODO Set up log drain etc */ export const logger = pino({ - level: "debug", + level: process.env.APP_DEBUG ?? "silent", transport: process.env.NODE_ENV === "development" ? {