Skip to content

Commit

Permalink
Remove invalid next test cases
Browse files Browse the repository at this point in the history
  • Loading branch information
socsieng committed Nov 1, 2024
1 parent dccf33f commit b683d61
Showing 1 changed file with 27 additions and 93 deletions.
120 changes: 27 additions & 93 deletions packages/tests-unit/tests/adapters/cache.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -114,36 +114,48 @@ describe("S3Cache", () => {
});

describe("fetch cache", () => {
it("Should retrieve cache from fetch cache when fetch cache is true", async () => {
it("Should retrieve cache from fetch cache when fetch cache is true (next 13.5+)", async () => {
await cache.get("key", { fetchCache: true });

expect(getFetchCacheSpy).toHaveBeenCalled();
});

it("Should retrieve cache from fetch cache when hint is fetch", async () => {
it("Should retrieve cache from fetch cache when hint is fetch (next14)", async () => {
await cache.get("key", { kindHint: "fetch" });

expect(getFetchCacheSpy).toHaveBeenCalled();
});

it("Should return null when tag cache last modified is -1", async () => {
tagCache.getLastModified.mockResolvedValueOnce(-1);
describe("next15", () => {
beforeEach(() => {
globalThis.isNextAfter15 = true;
});

const result = await cache.get("key", { kindHint: "fetch" });
it("Should retrieve cache from fetch cache when hint is fetch", async () => {
await cache.get("key", { kind: "FETCH" });

expect(getFetchCacheSpy).toHaveBeenCalled();
expect(result).toBeNull();
});
expect(getFetchCacheSpy).toHaveBeenCalled();
});

it("Should return null when incremental cache throws", async () => {
incrementalCache.get.mockRejectedValueOnce(
new Error("Error retrieving cache"),
);
it("Should return null when tag cache last modified is -1", async () => {
tagCache.getLastModified.mockResolvedValueOnce(-1);

const result = await cache.get("key", { kindHint: "fetch" });
const result = await cache.get("key", { kind: "FETCH" });

expect(getFetchCacheSpy).toHaveBeenCalled();
expect(result).toBeNull();
expect(getFetchCacheSpy).toHaveBeenCalled();
expect(result).toBeNull();
});

it("Should return null when incremental cache throws", async () => {
incrementalCache.get.mockRejectedValueOnce(
new Error("Error retrieving cache"),
);

const result = await cache.get("key", { kind: "FETCH" });

expect(getFetchCacheSpy).toHaveBeenCalled();
expect(result).toBeNull();
});
});
});

Expand Down Expand Up @@ -193,28 +205,6 @@ describe("S3Cache", () => {
});
});

it("Should return value when cache data type is route for next 15 and later", async () => {
incrementalCache.get.mockResolvedValueOnce({
value: {
type: "route",
body: "{}",
},
lastModified: Date.now(),
});
globalThis.isNextAfter15 = true;

const result = await cache.get("key", { kindHint: "app" });

expect(getIncrementalCache).toHaveBeenCalled();
expect(result).toEqual({
value: {
kind: "APP_ROUTE",
body: Buffer.from("{}"),
},
lastModified: Date.now(),
});
});

it("Should return base64 encoded value when cache data type is route and content is binary", async () => {
incrementalCache.get.mockResolvedValueOnce({
value: {
Expand Down Expand Up @@ -271,34 +261,6 @@ describe("S3Cache", () => {
});
});

it("Should return value when cache data type is app for next 15 and later", async () => {
incrementalCache.get.mockResolvedValueOnce({
value: {
type: "app",
html: "<html></html>",
rsc: "rsc",
meta: {
status: 200,
},
},
lastModified: Date.now(),
});
globalThis.isNextAfter15 = true;

const result = await cache.get("key", { kindHint: "app" });

expect(getIncrementalCache).toHaveBeenCalled();
expect(result).toEqual({
value: {
kind: "APP_PAGE",
html: "<html></html>",
rscData: Buffer.from("rsc"),
status: 200,
},
lastModified: Date.now(),
});
});

it("Should return value when cache data type is page", async () => {
incrementalCache.get.mockResolvedValueOnce({
value: {
Expand Down Expand Up @@ -326,34 +288,6 @@ describe("S3Cache", () => {
});
});

it("Should return value when cache data type is page for next15 and later", async () => {
incrementalCache.get.mockResolvedValueOnce({
value: {
type: "page",
html: "<html></html>",
json: {},
meta: {
status: 200,
},
},
lastModified: Date.now(),
});
globalThis.isNextAfter15 = true;

const result = await cache.get("key", { kindHint: "pages" });

expect(getIncrementalCache).toHaveBeenCalled();
expect(result).toEqual({
value: {
kind: "PAGES",
html: "<html></html>",
pageData: {},
status: 200,
},
lastModified: Date.now(),
});
});

it("Should return value when cache data type is redirect", async () => {
incrementalCache.get.mockResolvedValueOnce({
value: {
Expand Down

0 comments on commit b683d61

Please sign in to comment.