release: WRNexusJS 0.8.0
This commit is contained in:
@@ -1,6 +1,8 @@
|
||||
import { afterEach, expect, test } from "bun:test";
|
||||
import {
|
||||
MobileUnavailableError,
|
||||
PushNotifications,
|
||||
SecureStorage,
|
||||
invoke,
|
||||
isNative,
|
||||
platform,
|
||||
@@ -59,3 +61,24 @@ test("explains missing plugins", async () => {
|
||||
root.Capacitor = { isNativePlatform: () => true, Plugins: {} };
|
||||
expect(invoke("Camera", "getPhoto")).rejects.toBeInstanceOf(MobileUnavailableError);
|
||||
});
|
||||
|
||||
test("normalizes push permission and rejects empty registrations", async () => {
|
||||
const push = new PushNotifications({
|
||||
permission: async () => "prompt",
|
||||
requestPermission: async () => "granted",
|
||||
register: async () => ({ token: "device-token", platform: "ios" }),
|
||||
});
|
||||
expect(await push.register()).toEqual({ token: "device-token", platform: "ios" });
|
||||
});
|
||||
|
||||
test("namespaces and validates secure-storage keys", async () => {
|
||||
const values = new Map<string, string>();
|
||||
const storage = new SecureStorage({
|
||||
get: async (key) => values.get(key) ?? null,
|
||||
set: async (key, value) => void values.set(key, value),
|
||||
remove: async (key) => void values.delete(key),
|
||||
});
|
||||
await storage.set("session", "encrypted-value");
|
||||
expect(values.get("wrnexus:session")).toBe("encrypted-value");
|
||||
expect(() => storage.get("bad key")).toThrow(TypeError);
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user