From 5f3ddebb2f0ed6403ed4333ff67c187a6c797abc Mon Sep 17 00:00:00 2001
From: Tanuj Kumar Mishra <tanuj077@users.noreply.github.com>
Date: Wed, 30 Nov 2022 12:10:42 +0000
Subject: [PATCH] adding test case for reading key from input

---
 __tests__/save.test.ts | 34 ++++++++++++++++++++++++++++++++++
 1 file changed, 34 insertions(+)

diff --git a/__tests__/save.test.ts b/__tests__/save.test.ts
index 4a3ae39..81881a5 100644
--- a/__tests__/save.test.ts
+++ b/__tests__/save.test.ts
@@ -389,3 +389,37 @@ test("save with valid inputs uploads a cache", async () => {
 
     expect(failedMock).toHaveBeenCalledTimes(0);
 });
+
+test("save with no primary key in state reads key from input", async () => {
+    const logWarningMock = jest.spyOn(actionUtils, "logWarning");
+    const failedMock = jest.spyOn(core, "setFailed");
+
+    const savedCacheKey = "Linux-node-bb828da54c148048dd17899ba9fda624811cfb43";
+    const primaryKey = "Linux-node-";
+    jest.spyOn(core, "getInput")
+        // Cache Entry Input
+        .mockImplementationOnce(() => {
+            return savedCacheKey;
+        })
+        // Cache Key Input
+        .mockImplementationOnce(() => {
+            return primaryKey;
+        });
+
+    const inputPath = "node_modules";
+    testUtils.setInput(Inputs.Path, inputPath);
+    testUtils.setInput(Inputs.UploadChunkSize, "4000000");
+
+    const cacheId = 4;
+    const saveCacheMock = jest
+        .spyOn(cache, "saveCache")
+        .mockImplementationOnce(() => {
+            return Promise.resolve(cacheId);
+        });
+
+    await run();
+
+    expect(saveCacheMock).toHaveBeenCalledTimes(1);
+    expect(logWarningMock).toHaveBeenCalledTimes(0);
+    expect(failedMock).toHaveBeenCalledTimes(0);
+});