Skip to content

Commit

Permalink
fix: use correct Shared Slices endpoints
Browse files Browse the repository at this point in the history
  • Loading branch information
angeloashmore committed Jul 14, 2021
1 parent bca09cd commit 5e073be
Show file tree
Hide file tree
Showing 12 changed files with 32 additions and 32 deletions.
10 changes: 5 additions & 5 deletions src/client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -241,7 +241,7 @@ export class CustomTypesClient {
async getAllSharedSlices<TSharedSliceModel extends prismicT.SharedSliceModel>(
params?: CustomTypesClientMethodParams,
): Promise<TSharedSliceModel[]> {
return await this.fetch<TSharedSliceModel[]>("slices", params);
return await this.fetch<TSharedSliceModel[]>("/slices", params);
}

/**
Expand All @@ -260,7 +260,7 @@ export class CustomTypesClient {
id: string,
params?: CustomTypesClientMethodParams,
): Promise<TSharedSliceModel> {
return await this.fetch<TSharedSliceModel>(`slices/${id}`, params);
return await this.fetch<TSharedSliceModel>(`/slices/${id}`, params);
}

/**
Expand All @@ -281,7 +281,7 @@ export class CustomTypesClient {
params?: CustomTypesClientMethodParams,
): Promise<TSharedSliceModel> {
await this.fetch(
"slices/insert",
"/slices/insert",
params,
createPostFetchRequestInit(slice),
);
Expand All @@ -307,7 +307,7 @@ export class CustomTypesClient {
params?: CustomTypesClientMethodParams,
): Promise<TSharedSliceModel> {
await this.fetch(
"slices/update",
"/slices/update",
params,
createPostFetchRequestInit(slice),
);
Expand All @@ -330,7 +330,7 @@ export class CustomTypesClient {
id: TSharedSliceID,
params?: CustomTypesClientMethodParams,
): Promise<TSharedSliceID> {
await this.fetch(`slices/${id}`, params, {
await this.fetch(`/slices/${id}`, params, {
method: "delete",
});

Expand Down
4 changes: 2 additions & 2 deletions test/__testutils__/createCustomType.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@ import * as prismic from "../../src";
export const createCustomType = <
CustomTypeModel extends prismicT.CustomTypeModel,
>(
overrides?: Partial<prismic.CustomType<CustomTypeModel>>,
): prismic.CustomType<CustomTypeModel> => {
overrides?: Partial<prismic.CustomType<string, CustomTypeModel>>,
): prismic.CustomType<string, CustomTypeModel> => {
const id = Math.random().toString();
const label = Math.random().toString();

Expand Down
2 changes: 1 addition & 1 deletion test/client-getAll.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ test("returns all Custom Types", async (t) => {
test("uses params if provided", async (t) => {
const queryResponse = [createCustomType()];
const client = createClient(t);
const params: Required<prismicCustomTypes.CustomTypesAPIParams> = {
const params: Required<prismicCustomTypes.CustomTypesClientMethodParams> = {
repositoryName: "custom-repositoryName",
token: "custom-token",
endpoint: "https://custom-endpoint.example.com",
Expand Down
6 changes: 3 additions & 3 deletions test/client-getAllSharedSlices.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ test("returns all Shared Slices", async (t) => {
const client = createClient(t);

server.use(
msw.rest.get(resolveURL(client.endpoint, "slices"), (req, res, ctx) => {
msw.rest.get(resolveURL(client.endpoint, "/slices"), (req, res, ctx) => {
if (!isAuthorizedRequest(client, req)) {
return res(
ctx.status(403),
Expand All @@ -38,14 +38,14 @@ test("returns all Shared Slices", async (t) => {
test("uses params if provided", async (t) => {
const queryResponse = [createSharedSlice()];
const client = createClient(t);
const params: Required<prismicCustomTypes.CustomTypesAPIParams> = {
const params: Required<prismicCustomTypes.CustomTypesClientMethodParams> = {
repositoryName: "custom-repositoryName",
token: "custom-token",
endpoint: "https://custom-endpoint.example.com",
};

server.use(
msw.rest.get(resolveURL(params.endpoint, "slices"), (req, res, ctx) => {
msw.rest.get(resolveURL(params.endpoint, "/slices"), (req, res, ctx) => {
if (!isAuthorizedRequest(params, req)) {
return res(
ctx.status(403),
Expand Down
2 changes: 1 addition & 1 deletion test/client-getByID.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ test("returns a Custom Type by ID", async (t) => {
test("uses params if provided", async (t) => {
const customType = createCustomType();
const client = createClient(t);
const params: Required<prismicCustomTypes.CustomTypesAPIParams> = {
const params: Required<prismicCustomTypes.CustomTypesClientMethodParams> = {
repositoryName: "custom-repositoryName",
token: "custom-token",
endpoint: "https://custom-endpoint.example.com",
Expand Down
8 changes: 4 additions & 4 deletions test/client-getSharedSliceByID.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ test("returns a Shared Slice by ID", async (t) => {

server.use(
msw.rest.get(
resolveURL(client.endpoint, `slices/${sharedSlice.id}`),
resolveURL(client.endpoint, `/slices/${sharedSlice.id}`),
(req, res, ctx) => {
if (!isAuthorizedRequest(client, req)) {
return res(
Expand All @@ -41,15 +41,15 @@ test("returns a Shared Slice by ID", async (t) => {
test("uses params if provided", async (t) => {
const sharedSlice = createSharedSlice();
const client = createClient(t);
const params: Required<prismicCustomTypes.CustomTypesAPIParams> = {
const params: Required<prismicCustomTypes.CustomTypesClientMethodParams> = {
repositoryName: "custom-repositoryName",
token: "custom-token",
endpoint: "https://custom-endpoint.example.com",
};

server.use(
msw.rest.get(
resolveURL(params.endpoint, `slices/${sharedSlice.id}`),
resolveURL(params.endpoint, `/slices/${sharedSlice.id}`),
(req, res, ctx) => {
if (!isAuthorizedRequest(params, req)) {
return res(
Expand All @@ -74,7 +74,7 @@ test("throws NotFoundError if a matching Custom Type was not found", async (t) =

server.use(
msw.rest.get(
resolveURL(client.endpoint, `slices/${sharedSlice.id}`),
resolveURL(client.endpoint, `/slices/${sharedSlice.id}`),
(req, res, ctx) => {
if (!isAuthorizedRequest(client, req)) {
return res(
Expand Down
2 changes: 1 addition & 1 deletion test/client-insert.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ test("inserts a Custom Type", async (t) => {
test("uses params if provided", async (t) => {
const customType = createCustomType();
const client = createClient(t);
const params: Required<prismicCustomTypes.CustomTypesAPIParams> = {
const params: Required<prismicCustomTypes.CustomTypesClientMethodParams> = {
repositoryName: "custom-repositoryName",
token: "custom-token",
endpoint: "https://custom-endpoint.example.com",
Expand Down
10 changes: 5 additions & 5 deletions test/client-insertSharedSlice.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ test("inserts a Shared Slice", async (t) => {

server.use(
msw.rest.post(
resolveURL(client.endpoint, "slices/insert"),
resolveURL(client.endpoint, "/slices/insert"),
(req, res, ctx) => {
if (!isAuthorizedRequest(client, req)) {
return res(
Expand All @@ -44,15 +44,15 @@ test("inserts a Shared Slice", async (t) => {
test("uses params if provided", async (t) => {
const sharedSlice = createSharedSlice();
const client = createClient(t);
const params: Required<prismicCustomTypes.CustomTypesAPIParams> = {
const params: Required<prismicCustomTypes.CustomTypesClientMethodParams> = {
repositoryName: "custom-repositoryName",
token: "custom-token",
endpoint: "https://custom-endpoint.example.com",
};

server.use(
msw.rest.post(
resolveURL(params.endpoint, "slices/insert"),
resolveURL(params.endpoint, "/slices/insert"),
(req, res, ctx) => {
if (!isAuthorizedRequest(params, req)) {
return res(
Expand All @@ -79,7 +79,7 @@ test("throws ConflictError if a Custom Type with the same ID already exists", as

server.use(
msw.rest.post(
resolveURL(client.endpoint, "slices/insert"),
resolveURL(client.endpoint, "/slices/insert"),
(req, res, ctx) => {
if (!isAuthorizedRequest(client, req)) {
return res(
Expand Down Expand Up @@ -107,7 +107,7 @@ test("throws InvalidPayloadError if an invalid Shared Slice is sent", async (t)

server.use(
msw.rest.post(
resolveURL(client.endpoint, "slices/insert"),
resolveURL(client.endpoint, "/slices/insert"),
(req, res, ctx) => {
if (!isAuthorizedRequest(client, req)) {
return res(
Expand Down
2 changes: 1 addition & 1 deletion test/client-remove.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ test("removes a Custom Type", async (t) => {
test("uses params if provided", async (t) => {
const customType = createCustomType();
const client = createClient(t);
const params: Required<prismicCustomTypes.CustomTypesAPIParams> = {
const params: Required<prismicCustomTypes.CustomTypesClientMethodParams> = {
repositoryName: "custom-repositoryName",
token: "custom-token",
endpoint: "https://custom-endpoint.example.com",
Expand Down
6 changes: 3 additions & 3 deletions test/client-removeSharedSlice.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ test("removes a Shared Slice", async (t) => {

server.use(
msw.rest.delete(
resolveURL(client.endpoint, `slices/${sharedSlice.id}`),
resolveURL(client.endpoint, `/slices/${sharedSlice.id}`),
(req, res, ctx) => {
if (!isAuthorizedRequest(client, req)) {
return res(
Expand All @@ -41,15 +41,15 @@ test("removes a Shared Slice", async (t) => {
test("uses params if provided", async (t) => {
const sharedSlice = createSharedSlice();
const client = createClient(t);
const params: Required<prismicCustomTypes.CustomTypesAPIParams> = {
const params: Required<prismicCustomTypes.CustomTypesClientMethodParams> = {
repositoryName: "custom-repositoryName",
token: "custom-token",
endpoint: "https://custom-endpoint.example.com",
};

server.use(
msw.rest.delete(
resolveURL(params.endpoint, `slices/${sharedSlice.id}`),
resolveURL(params.endpoint, `/slices/${sharedSlice.id}`),
(req, res, ctx) => {
if (!isAuthorizedRequest(params, req)) {
return res(
Expand Down
2 changes: 1 addition & 1 deletion test/client-update.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ test("updates a Custom Type", async (t) => {
test("uses params if provided", async (t) => {
const customType = createCustomType();
const client = createClient(t);
const params: Required<prismicCustomTypes.CustomTypesAPIParams> = {
const params: Required<prismicCustomTypes.CustomTypesClientMethodParams> = {
repositoryName: "custom-repositoryName",
token: "custom-token",
endpoint: "https://custom-endpoint.example.com",
Expand Down
10 changes: 5 additions & 5 deletions test/client-updateSharedSlice.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ test("updates a Custom Type", async (t) => {

server.use(
msw.rest.post(
resolveURL(client.endpoint, "slices/update"),
resolveURL(client.endpoint, "/slices/update"),
(req, res, ctx) => {
if (!isAuthorizedRequest(client, req)) {
return res(
Expand All @@ -44,15 +44,15 @@ test("updates a Custom Type", async (t) => {
test("uses params if provided", async (t) => {
const customType = createSharedSlice();
const client = createClient(t);
const params: Required<prismicCustomTypes.CustomTypesAPIParams> = {
const params: Required<prismicCustomTypes.CustomTypesClientMethodParams> = {
repositoryName: "custom-repositoryName",
token: "custom-token",
endpoint: "https://custom-endpoint.example.com",
};

server.use(
msw.rest.post(
resolveURL(params.endpoint, "slices/update"),
resolveURL(params.endpoint, "/slices/update"),
(req, res, ctx) => {
if (!isAuthorizedRequest(params, req)) {
return res(
Expand All @@ -79,7 +79,7 @@ test("throws NotFoundError if a matching Custom Type was not found", async (t) =

server.use(
msw.rest.post(
resolveURL(client.endpoint, "slices/update"),
resolveURL(client.endpoint, "/slices/update"),
(req, res, ctx) => {
if (!isAuthorizedRequest(client, req)) {
return res(
Expand Down Expand Up @@ -107,7 +107,7 @@ test("throws InvalidPayloadError if an invalid Shared Slice is sent", async (t)

server.use(
msw.rest.post(
resolveURL(client.endpoint, "slices/update"),
resolveURL(client.endpoint, "/slices/update"),
(req, res, ctx) => {
if (!isAuthorizedRequest(client, req)) {
return res(
Expand Down

0 comments on commit 5e073be

Please sign in to comment.