UNPKG

@kilterset/auth0-actions-testing

Version:

Test and develop Auth0 Actions or Okta CIC Actions locally.

63 lines 3.59 kB
"use strict"; var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) { function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); } return new (P || (P = Promise))(function (resolve, reject) { function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } } function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } } function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); } step((generator = generator.apply(thisArg, _arguments || [])).next()); }); }; var __importDefault = (this && this.__importDefault) || function (mod) { return (mod && mod.__esModule) ? mod : { "default": mod }; }; Object.defineProperty(exports, "__esModule", { value: true }); const node_test_1 = __importDefault(require("node:test")); const node_assert_1 = require("node:assert"); const api_1 = require("../../mock/api"); const NOW = Date.now(); const ONE_DAY_IN_MS = 24 * 60 * 60 * 1000; const FIFTEEN_MINS_IN_MS = 15 * 60 * 1000; const ONE_DAY_FROM_NOW = NOW + ONE_DAY_IN_MS; const FIFTEEN_MINS_FROM_NOW = NOW + FIFTEEN_MINS_IN_MS; (0, node_test_1.default)("Mock cache API", (t) => __awaiter(void 0, void 0, void 0, function* () { t.mock.method(Date, "now", () => NOW); yield t.test("supports basic operations", (t) => __awaiter(void 0, void 0, void 0, function* () { const cache = (0, api_1.cache)(); (0, node_assert_1.strictEqual)(cache.get("juicebox"), undefined); (0, node_assert_1.deepStrictEqual)(cache.set("juicebox", "apple"), { type: "success", record: { value: "apple", expires_at: FIFTEEN_MINS_FROM_NOW }, }); (0, node_assert_1.strictEqual)(cache.get("juicebox"), "apple"); (0, node_assert_1.deepStrictEqual)(cache.delete("juicebox"), { type: "success" }); (0, node_assert_1.strictEqual)(cache.get("juicebox"), undefined); (0, node_assert_1.deepStrictEqual)(cache.delete("juicebox"), { type: "error", code: "CacheKeyDoesNotExist", }); })); yield t.test("supports mock preconditions", (t) => __awaiter(void 0, void 0, void 0, function* () { const cache = (0, api_1.cache)({ sandwich: "ham" }); (0, node_assert_1.strictEqual)(cache.get("sandwich"), "ham"); cache.set("sandwich", "tuna"); (0, node_assert_1.strictEqual)(cache.get("sandwich"), "tuna"); })); yield t.test("setting with ttl", (t) => __awaiter(void 0, void 0, void 0, function* () { const cache = (0, api_1.cache)(); cache.set("one-day-ttl", "ok", { ttl: ONE_DAY_IN_MS }); t.mock.method(Date, "now", () => ONE_DAY_FROM_NOW - 1); (0, node_assert_1.strictEqual)(cache.get("one-day-ttl"), "ok"); t.mock.method(Date, "now", () => ONE_DAY_FROM_NOW); (0, node_assert_1.strictEqual)(cache.get("one-day-ttl"), undefined); })); yield t.test("setting with expires_at", (t) => __awaiter(void 0, void 0, void 0, function* () { const cache = (0, api_1.cache)(); cache.set("one-day-expiry", "ok", { expires_at: ONE_DAY_FROM_NOW }); t.mock.method(Date, "now", () => ONE_DAY_FROM_NOW - 1); (0, node_assert_1.strictEqual)(cache.get("one-day-expiry"), "ok"); t.mock.method(Date, "now", () => ONE_DAY_FROM_NOW); (0, node_assert_1.strictEqual)(cache.get("one-day-expiry"), undefined); })); })); //# sourceMappingURL=cache.test.js.map