-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
schedule create metaobject in shopify
- Loading branch information
1 parent
4c63301
commit 0788f11
Showing
8 changed files
with
272 additions
and
8 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,18 +1,101 @@ | ||
import { CustomerScheduleServiceCreate } from "./create"; | ||
import { ensureType } from "~/library/jest/helpers/mock"; | ||
import { shopifyAdmin } from "~/library/shopify"; | ||
import { | ||
CreateScheduleMetaobjectMutation, | ||
CreateScheduleMetaobjectMutationVariables, | ||
} from "~/types/admin.generated"; | ||
import { | ||
CREATE_SCHEDULE_METAOBJECT, | ||
CustomerScheduleServiceCreate, | ||
} from "./create"; | ||
|
||
require("~/library/jest/mongoose/mongodb.jest"); | ||
|
||
jest.mock("@shopify/admin-api-client", () => ({ | ||
createAdminApiClient: () => ({ | ||
request: jest.fn(), | ||
}), | ||
})); | ||
|
||
const mockRequest = shopifyAdmin.request as jest.Mock; | ||
|
||
describe("CustomerScheduleServiceCreate", () => { | ||
const customerId = 123; | ||
const name = "Test Schedule"; | ||
|
||
it("should create a new schedule", async () => { | ||
mockRequest.mockResolvedValueOnce({ | ||
data: ensureType<CreateScheduleMetaobjectMutation>({ | ||
metaobjectCreate: { | ||
metaobject: { | ||
id: "gid://shopify/Metaobject/77850968391", | ||
type: "schedule", | ||
fields: [ | ||
{ | ||
value: name, | ||
key: "name", | ||
}, | ||
{ | ||
value: JSON.stringify([ | ||
{ | ||
day: "monday", | ||
intervals: [ | ||
{ | ||
to: "16:00", | ||
from: "08:00", | ||
}, | ||
], | ||
}, | ||
]), | ||
key: "slots", | ||
}, | ||
], | ||
}, | ||
}, | ||
}), | ||
}); | ||
|
||
const newSchedule = await CustomerScheduleServiceCreate({ | ||
name, | ||
customerId, | ||
}); | ||
|
||
expect(shopifyAdmin.request).toHaveBeenCalledTimes(1); | ||
|
||
expect(shopifyAdmin.request).toHaveBeenNthCalledWith( | ||
1, | ||
CREATE_SCHEDULE_METAOBJECT, | ||
{ | ||
variables: ensureType<CreateScheduleMetaobjectMutationVariables>({ | ||
handle: newSchedule._id, | ||
fields: [ | ||
{ | ||
value: newSchedule.name, | ||
key: "name", | ||
}, | ||
{ | ||
value: JSON.stringify([ | ||
{ | ||
day: "monday", | ||
intervals: [ | ||
{ | ||
to: "16:00", | ||
from: "08:00", | ||
}, | ||
], | ||
}, | ||
]), | ||
key: "slots", | ||
}, | ||
], | ||
}), | ||
} | ||
); | ||
|
||
expect(newSchedule.name).toEqual(name); | ||
expect(newSchedule.metafieldId).toEqual( | ||
"gid://shopify/Metaobject/77850968391" | ||
); | ||
expect(newSchedule.customerId).toEqual(customerId); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters