Skip to content

Commit

Permalink
disallow setting version when prefix is set (useblacksmith#13)
Browse files Browse the repository at this point in the history
  • Loading branch information
aayushshah15 authored Nov 26, 2024
1 parent 32651f9 commit c27f005
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 0 deletions.
3 changes: 3 additions & 0 deletions dist/index.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

11 changes: 11 additions & 0 deletions src/__tests__/main.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -154,6 +154,17 @@ describe("deleteCache", () => {
).rejects.toThrow("Cache key cannot be empty unless prefix is true");
});

it("should fail if version is specified with prefix", async () => {
await expect(
deleteCache({
cacheKey: "npm-cache",
cacheVersion: "v1.0",
prefix: true,
...defaultParams,
})
).rejects.toThrow("Cannot specify version when using prefix");
});

it("should handle 404 response", async () => {
mockedFetch.mockResolvedValue({
ok: false,
Expand Down
3 changes: 3 additions & 0 deletions src/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,9 @@ export async function deleteCache({
if (cacheVersion && !cacheKey) {
throw new Error("Cannot specify version when using empty key");
}
if (prefix && cacheVersion) {
throw new Error("Cannot specify version when using prefix");
}

const resource = cacheVersion ? `${cacheKey}/${cacheVersion}` : cacheKey;
const url = `${baseUrl}/caches/${resource}`;
Expand Down

0 comments on commit c27f005

Please sign in to comment.