Skip to content

Commit

Permalink
add multiply keys to to remove pressure from shopify limit
Browse files Browse the repository at this point in the history
  • Loading branch information
jamalsoueidan committed May 28, 2024
1 parent 111d52e commit 81ae258
Show file tree
Hide file tree
Showing 53 changed files with 412 additions and 438 deletions.
6 changes: 3 additions & 3 deletions src/functions/customer/controllers/product/add.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,13 +29,13 @@ jest.mock("../../orchestrations/product/update", () => ({
}),
}));

jest.mock("@shopify/admin-api-client", () => ({
createAdminApiClient: () => ({
jest.mock("~/library/shopify", () => ({
shopifyAdmin: jest.fn().mockReturnValue({
request: jest.fn(),
}),
}));

const mockRequest = shopifyAdmin.request as jest.Mock;
const mockRequest = shopifyAdmin().request as jest.Mock;

describe("CustomerProductControllerAdd", () => {
let context: InvocationContext;
Expand Down
6 changes: 3 additions & 3 deletions src/functions/customer/controllers/product/destroy.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,13 +18,13 @@ import {

require("~/library/jest/mongoose/mongodb.jest");

jest.mock("@shopify/admin-api-client", () => ({
createAdminApiClient: () => ({
jest.mock("~/library/shopify", () => ({
shopifyAdmin: jest.fn().mockReturnValue({
request: jest.fn(),
}),
}));

const mockRequest = shopifyAdmin.request as jest.Mock;
const mockRequest = shopifyAdmin().request as jest.Mock;

describe("CustomerProductControllerDestroy", () => {
let context: InvocationContext;
Expand Down
6 changes: 3 additions & 3 deletions src/functions/customer/controllers/schedule/create.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,13 +15,13 @@ import {

require("~/library/jest/mongoose/mongodb.jest");

jest.mock("@shopify/admin-api-client", () => ({
createAdminApiClient: () => ({
jest.mock("~/library/shopify", () => ({
shopifyAdmin: jest.fn().mockReturnValue({
request: jest.fn(),
}),
}));

const mockRequest = shopifyAdmin.request as jest.Mock;
const mockRequest = shopifyAdmin().request as jest.Mock;

describe("CustomerScheduleControllerCreate", () => {
let context: InvocationContext;
Expand Down
6 changes: 3 additions & 3 deletions src/functions/customer/controllers/schedule/destroy.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,13 +16,13 @@ import {

require("~/library/jest/mongoose/mongodb.jest");

jest.mock("@shopify/admin-api-client", () => ({
createAdminApiClient: () => ({
jest.mock("~/library/shopify", () => ({
shopifyAdmin: jest.fn().mockReturnValue({
request: jest.fn(),
}),
}));

const mockRequest = shopifyAdmin.request as jest.Mock;
const mockRequest = shopifyAdmin().request as jest.Mock;

describe("CustomerScheduleControllerDestroy", () => {
let context: InvocationContext;
Expand Down
6 changes: 3 additions & 3 deletions src/functions/customer/controllers/schedule/update.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,13 +18,13 @@ import {

require("~/library/jest/mongoose/mongodb.jest");

jest.mock("@shopify/admin-api-client", () => ({
createAdminApiClient: () => ({
jest.mock("~/library/shopify", () => ({
shopifyAdmin: jest.fn().mockReturnValue({
request: jest.fn(),
}),
}));

const mockRequest = shopifyAdmin.request as jest.Mock;
const mockRequest = shopifyAdmin().request as jest.Mock;

describe("CustomerScheduleControllerUpdate", () => {
let context: InvocationContext;
Expand Down
6 changes: 3 additions & 3 deletions src/functions/customer/controllers/slot/update.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,13 +19,13 @@ import {

require("~/library/jest/mongoose/mongodb.jest");

jest.mock("@shopify/admin-api-client", () => ({
createAdminApiClient: () => ({
jest.mock("~/library/shopify", () => ({
shopifyAdmin: jest.fn().mockReturnValue({
request: jest.fn(),
}),
}));

const mockRequest = shopifyAdmin.request as jest.Mock;
const mockRequest = shopifyAdmin().request as jest.Mock;

describe("CustomerScheduleSlotControllerUpdate", () => {
let context: InvocationContext;
Expand Down
2 changes: 1 addition & 1 deletion src/functions/customer/controllers/upload/file-create.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { shopifyAdmin } from "~/library/shopify";
import { FileInputProps, getFilenameFromUrl } from "./types";

export async function fileCreateHandler(input: FileInputProps) {
const { data } = await shopifyAdmin.request(FILE_CREATE, {
const { data } = await shopifyAdmin().request(FILE_CREATE, {
variables: {
files: {
alt: getFilenameFromUrl(input.resourceUrl),
Expand Down
2 changes: 1 addition & 1 deletion src/functions/customer/controllers/upload/file-get.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { shopifyAdmin } from "~/library/shopify";

export async function fileGetHandler(metaobjectId: string) {
const { data } = await shopifyAdmin.request(FILE_GET, {
const { data } = await shopifyAdmin().request(FILE_GET, {
variables: {
id: metaobjectId,
},
Expand Down
2 changes: 1 addition & 1 deletion src/functions/customer/controllers/upload/resource-url.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ export const CustomerUploadControllerResourceURL = _(
async ({ query }: CustomerUploadControllerResourceURLRequest) => {
const validateData =
CustomerUploadControllerResourceURLQuerySchema.parse(query);
const { data } = await shopifyAdmin.request(UPLOAD_CREATE, {
const { data } = await shopifyAdmin().request(UPLOAD_CREATE, {
variables: {
input: [
{
Expand Down
8 changes: 1 addition & 7 deletions src/functions/customer/orchestrations/customer/create.ts
Original file line number Diff line number Diff line change
Expand Up @@ -50,9 +50,6 @@ const orchestrator: df.OrchestrationHandler = function* (
})
);

let nextExecution = addSeconds(context.df.currentUtcDateTime, 5);
yield context.df.createTimer(nextExecution);

const article: Awaited<ReturnType<typeof createArticle>> =
yield context.df.callActivity(
createArticleName,
Expand All @@ -65,9 +62,6 @@ const orchestrator: df.OrchestrationHandler = function* (
})
);

nextExecution = addSeconds(context.df.currentUtcDateTime, 5);
yield context.df.createTimer(nextExecution);

const userUpdated: Awaited<ReturnType<typeof updateUserMetafields>> =
yield context.df.callActivity(
updateUserMetafieldsName,
Expand All @@ -79,7 +73,7 @@ const orchestrator: df.OrchestrationHandler = function* (
})
);

nextExecution = addSeconds(context.df.currentUtcDateTime, 5);
const nextExecution = addSeconds(context.df.currentUtcDateTime, 5);
yield context.df.createTimer(nextExecution);

const publish: Awaited<ReturnType<typeof publishCollection>> =
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ export const createArticle = async ({
)
);

const response = await shopifyRest.post("blogs/105364226375/articles", {
const response = await shopifyRest().post("blogs/105364226375/articles", {
data: {
article: {
blog_id: 105364226375,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,13 @@ import { COLLECTION_CREATE, createCollection } from "./create-collection";

require("~/library/jest/mongoose/mongodb.jest");

jest.mock("@shopify/admin-api-client", () => ({
createAdminApiClient: () => ({
jest.mock("~/library/shopify", () => ({
shopifyAdmin: jest.fn().mockReturnValue({
request: jest.fn(),
}),
}));

const mockRequest = shopifyAdmin.request as jest.Mock;
let mockRequest = shopifyAdmin().request as jest.Mock;

describe("CustomerCreateOrchestration", () => {
beforeAll(async () => {
Expand All @@ -39,9 +39,9 @@ describe("CustomerCreateOrchestration", () => {

await createCollection({ user });

expect(shopifyAdmin.request).toHaveBeenCalledTimes(1);
expect(mockRequest).toHaveBeenCalledTimes(1);

expect(shopifyAdmin.request).toHaveBeenNthCalledWith(1, COLLECTION_CREATE, {
expect(mockRequest).toHaveBeenNthCalledWith(1, COLLECTION_CREATE, {
variables: {
input: {
handle: user.username,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ export const createCollection = async ({
}: {
user: Pick<User, "username">;
}) => {
const { data } = await shopifyAdmin.request(COLLECTION_CREATE, {
const { data } = await shopifyAdmin().request(COLLECTION_CREATE, {
variables: {
input: {
handle: user.username,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,13 @@ import {

require("~/library/jest/mongoose/mongodb.jest");

jest.mock("@shopify/admin-api-client", () => ({
createAdminApiClient: () => ({
jest.mock("~/library/shopify", () => ({
shopifyAdmin: jest.fn().mockReturnValue({
request: jest.fn(),
}),
}));

const mockRequest = shopifyAdmin.request as jest.Mock;
const mockRequest = shopifyAdmin().request as jest.Mock;

describe("CustomerCreateOrchestration", () => {
beforeAll(async () => {
Expand Down Expand Up @@ -76,46 +76,46 @@ describe("CustomerCreateOrchestration", () => {
collectionId: "gid://shopify/Collection/625094558023",
});

expect(shopifyAdmin.request).toHaveBeenCalledTimes(1);
expect(mockRequest).toHaveBeenCalledTimes(1);

expect(shopifyAdmin.request).toHaveBeenNthCalledWith(
1,
CREATE_USER_METAOBJECT,
{
variables: {
handle: userData.username,
fields: [
{
key: "username",
value: userData.username,
},
{
key: "fullname",
value: userData.fullname,
},
{
key: "short_description",
value: userData.shortDescription || "",
},
{
key: "about_me",
value: userData.aboutMeHtml || "",
},
{
key: "professions",
value: JSON.stringify(userData.professions || []),
},
{
key: "collection",
value: collectionMetaobjectId,
},
{
key: "theme",
value: "pink",
},
],
},
}
);
expect(mockRequest).toHaveBeenNthCalledWith(1, CREATE_USER_METAOBJECT, {
variables: {
handle: userData.username,
fields: [
{
key: "username",
value: userData.username,
},
{
key: "fullname",
value: userData.fullname,
},
{
key: "short_description",
value: userData.shortDescription || "",
},
{
key: "about_me",
value: userData.aboutMeHtml || "",
},
{
key: "professions",
value: JSON.stringify(userData.professions || []),
},
{
key: "collection",
value: collectionMetaobjectId,
},
{
key: "theme",
value: "pink",
},
{
key: "active",
value: "False",
},
],
},
});
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ export const createUserMetaobject = async ({
user: Omit<User, "_id">;
collectionId: string;
}) => {
const { data } = await shopifyAdmin.request(CREATE_USER_METAOBJECT, {
const { data } = await shopifyAdmin().request(CREATE_USER_METAOBJECT, {
variables: {
handle: user.username,
fields: [
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,13 @@ import {

require("~/library/jest/mongoose/mongodb.jest");

jest.mock("@shopify/admin-api-client", () => ({
createAdminApiClient: () => ({
jest.mock("~/library/shopify", () => ({
shopifyAdmin: jest.fn().mockReturnValue({
request: jest.fn(),
}),
}));

const mockRequest = shopifyAdmin.request as jest.Mock;
const mockRequest = shopifyAdmin().request as jest.Mock;

describe("CustomerCreateOrchestration", () => {
beforeAll(async () => {
Expand Down Expand Up @@ -59,12 +59,12 @@ describe("CustomerCreateOrchestration", () => {
collectionId,
});

expect(shopifyAdmin.request).toHaveBeenCalledTimes(8);
expect(mockRequest).toHaveBeenCalledTimes(8);

expect(shopifyAdmin.request).toHaveBeenNthCalledWith(1, PUBLICATIONS);
expect(mockRequest).toHaveBeenNthCalledWith(1, PUBLICATIONS);

mockPublications.map((p, index) => {
expect(shopifyAdmin.request).toHaveBeenNthCalledWith(
expect(mockRequest).toHaveBeenNthCalledWith(
2 + index,
PUBLISH_COLLECTION,
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,15 +6,15 @@ export const publishCollection = async ({
}: {
collectionId: string;
}) => {
const { data } = await shopifyAdmin.request(PUBLICATIONS);
const { data } = await shopifyAdmin().request(PUBLICATIONS);

if (!data?.publications.nodes) {
throw new Error(`Failed to find any publichations for ${collectionId}`);
}

await Promise.all(
data.publications.nodes.map(async (pub) => {
return shopifyAdmin.request(PUBLISH_COLLECTION, {
return shopifyAdmin().request(PUBLISH_COLLECTION, {
variables: {
collectionId: collectionId,
publicationId: pub.id,
Expand Down
4 changes: 0 additions & 4 deletions src/functions/customer/orchestrations/customer/update.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import { InvocationContext } from "@azure/functions";
import { addSeconds } from "date-fns";
import * as df from "durable-functions";
import { OrchestrationContext } from "durable-functions";
import { User } from "~/functions/user";
Expand Down Expand Up @@ -31,9 +30,6 @@ const orchestrator: df.OrchestrationHandler = function* (
})
);

const nextExecution = addSeconds(context.df.currentUtcDateTime, 5);
yield context.df.createTimer(nextExecution);

const article: Awaited<ReturnType<typeof updateArticle>> =
yield context.df.callActivity(
updateArticleName,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ export const updateArticle = async ({

tags.push(`gender-${user.gender}`);

const response = await shopifyRest.put(
const response = await shopifyRest().put(
`blogs/105364226375/articles/${user.articleId}`,
{
data: {
Expand Down
Loading

0 comments on commit 81ae258

Please sign in to comment.