Skip to content

Commit

Permalink
feat: rename Custom Type-related methods to include "CustomType" (#2)
Browse files Browse the repository at this point in the history
  • Loading branch information
angeloashmore committed Mar 17, 2022
1 parent 38a8ded commit 999b3f7
Show file tree
Hide file tree
Showing 7 changed files with 57 additions and 24 deletions.
40 changes: 35 additions & 5 deletions src/client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -129,6 +129,12 @@ export class CustomTypesClient {
}
}

/**
* @deprecated Renamed to `getAllCustomTypes`.
*/
// TODO: Remove in v1.
getAll = this.getAllCustomTypes.bind(this);

/**
* Returns all Custom Types models from the Prismic repository.
*
Expand All @@ -138,12 +144,18 @@ export class CustomTypesClient {
* @returns All Custom Type models from the Prismic repository.
* @throws {@link ForbiddenError} Thrown if the client is unauthorized to make requests.
*/
async getAll<TCustomType extends prismicT.CustomTypeModel>(
async getAllCustomTypes<TCustomType extends prismicT.CustomTypeModel>(
params?: CustomTypesClientMethodParams,
): Promise<TCustomType[]> {
return await this.fetch<TCustomType[]>("", params);
}

/**
* @deprecated Renamed to `getCustomTypeByID`.
*/
// TODO: Remove in v1.
getByID = this.getCustomTypeByID.bind(this);

/**
* Returns a Custom Type model with a given ID from the Prismic repository.
*
Expand All @@ -156,13 +168,19 @@ export class CustomTypesClient {
* @throws {@link NotFoundError} Thrown if a Custom Type with the given ID
* cannot be found.
*/
async getByID<TCustomType extends prismicT.CustomTypeModel>(
async getCustomTypeByID<TCustomType extends prismicT.CustomTypeModel>(
id: string,
params?: CustomTypesClientMethodParams,
): Promise<TCustomType> {
return await this.fetch<TCustomType>(id, params);
}

/**
* @deprecated Renamed to `insertCustomType`.
*/
// TODO: Remove in v1.
insert = this.insertCustomType.bind(this);

/**
* Inserts a Custom Type model to the Prismic repository.
*
Expand All @@ -176,7 +194,7 @@ export class CustomTypesClient {
* @throws {@link ConflictError} Thrown if a Custom Type with the given ID
* already exists.
*/
async insert<TCustomType extends prismicT.CustomTypeModel>(
async insertCustomType<TCustomType extends prismicT.CustomTypeModel>(
customType: TCustomType,
params?: CustomTypesClientMethodParams,
): Promise<TCustomType> {
Expand All @@ -189,6 +207,12 @@ export class CustomTypesClient {
return customType;
}

/**
* @deprecated Renamed to `updateCustomType`.
*/
// TODO: Remove in v1.
update = this.updateCustomType.bind(this);

/**
* Updates a Custom Type model from the Prismic repository.
*
Expand All @@ -202,7 +226,7 @@ export class CustomTypesClient {
* @throws {@link NotFoundError} Thrown if a Custom Type with the given ID
* cannot be found.
*/
async update<TCustomType extends prismicT.CustomTypeModel>(
async updateCustomType<TCustomType extends prismicT.CustomTypeModel>(
customType: TCustomType,
params?: CustomTypesClientMethodParams,
): Promise<TCustomType> {
Expand All @@ -215,6 +239,12 @@ export class CustomTypesClient {
return customType;
}

/**
* @deprecated Renamed to `removeCustomType`.
*/
// TODO: Remove in v1.
remove = this.removeCustomType.bind(this);

/**
* Removes a Custom Type model from the Prismic repository.
*
Expand All @@ -225,7 +255,7 @@ export class CustomTypesClient {
* @returns The ID of the removed Custom Type.
* @throws {@link ForbiddenError} Thrown if the client is unauthorized to make requests.
*/
async remove<TCustomTypeID extends string>(
async removeCustomType<TCustomTypeID extends string>(
id: TCustomTypeID,
params?: CustomTypesClientMethodParams,
): Promise<TCustomTypeID> {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ test("returns all Custom Types", async (t) => {
}),
);

const res = await client.getAll();
const res = await client.getAllCustomTypes();

t.deepEqual(res, queryResponse);
});
Expand All @@ -56,7 +56,7 @@ test("uses params if provided", async (t) => {
}),
);

const res = await client.getAll(params);
const res = await client.getAllCustomTypes(params);

t.deepEqual(res, queryResponse);
});
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ test("returns a Custom Type by ID", async (t) => {
),
);

const res = await client.getByID(customType.id);
const res = await client.getCustomTypeByID(customType.id);

t.deepEqual(res, customType);
});
Expand Down Expand Up @@ -63,7 +63,7 @@ test("uses params if provided", async (t) => {
),
);

const res = await client.getByID(customType.id, params);
const res = await client.getCustomTypeByID(customType.id, params);

t.deepEqual(res, customType);
});
Expand All @@ -88,7 +88,10 @@ test("throws NotFoundError if a matching Custom Type was not found", async (t) =
),
);

await t.throwsAsync(async () => await client.getByID(customType.id), {
instanceOf: prismicCustomTypes.NotFoundError,
});
await t.throwsAsync(
async () => await client.getCustomTypeByID(customType.id),
{
instanceOf: prismicCustomTypes.NotFoundError,
},
);
});
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ test("inserts a Custom Type", async (t) => {
}),
);

const res = await client.insert(customType);
const res = await client.insertCustomType(customType);

t.deepEqual(res, customType);
});
Expand Down Expand Up @@ -62,7 +62,7 @@ test("uses params if provided", async (t) => {
}),
);

const res = await client.insert(customType, params);
const res = await client.insertCustomType(customType, params);

t.deepEqual(res, customType);
});
Expand All @@ -86,7 +86,7 @@ test("throws ConflictError if a Custom Type with the same ID already exists", as
}),
);

await t.throwsAsync(async () => await client.insert(customType), {
await t.throwsAsync(async () => await client.insertCustomType(customType), {
instanceOf: prismicCustomTypes.ConflictError,
});
});
Expand All @@ -111,7 +111,7 @@ test("throws InvalidPayloadError if an invalid Custom Type is sent", async (t) =
}),
);

await t.throwsAsync(async () => await client.insert(customType), {
await t.throwsAsync(async () => await client.insertCustomType(customType), {
instanceOf: prismicCustomTypes.InvalidPayloadError,
message,
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ test("removes a Custom Type", async (t) => {
),
);

const res = await client.remove(customType.id);
const res = await client.removeCustomType(customType.id);

t.deepEqual(res, customType.id);
});
Expand Down Expand Up @@ -63,7 +63,7 @@ test("uses params if provided", async (t) => {
),
);

const res = await client.remove(customType.id, params);
const res = await client.removeCustomType(customType.id, params);

t.deepEqual(res, customType.id);
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ test("updates a Custom Type", async (t) => {
}),
);

const res = await client.update(customType);
const res = await client.updateCustomType(customType);

t.deepEqual(res, customType);
});
Expand Down Expand Up @@ -62,7 +62,7 @@ test("uses params if provided", async (t) => {
}),
);

const res = await client.update(customType, params);
const res = await client.updateCustomType(customType, params);

t.deepEqual(res, customType);
});
Expand All @@ -86,7 +86,7 @@ test("throws NotFoundError if a matching Custom Type was not found", async (t) =
}),
);

await t.throwsAsync(async () => await client.update(customType), {
await t.throwsAsync(async () => await client.updateCustomType(customType), {
instanceOf: prismicCustomTypes.NotFoundError,
});
});
Expand All @@ -111,7 +111,7 @@ test("throws InvalidPayloadError if an invalid Custom Type is sent", async (t) =
}),
);

await t.throwsAsync(async () => await client.update(customType), {
await t.throwsAsync(async () => await client.updateCustomType(customType), {
instanceOf: prismicCustomTypes.InvalidPayloadError,
message,
});
Expand Down
4 changes: 2 additions & 2 deletions test/client.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ test("throws ForbiddenError if unauthorized", async (t) => {
}),
);

await t.throwsAsync(async () => await client.getAll(), {
await t.throwsAsync(async () => await client.getAllCustomTypes(), {
instanceOf: prismicCustomTypes.ForbiddenError,
});
});
Expand All @@ -108,7 +108,7 @@ test("throws PrismicError if an unsupported response is returned", async (t) =>
}),
);

await t.throwsAsync(async () => await client.getAll(), {
await t.throwsAsync(async () => await client.getAllCustomTypes(), {
instanceOf: prismicCustomTypes.PrismicError,
});
});

0 comments on commit 999b3f7

Please sign in to comment.