-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathadapter.spec.ts
71 lines (65 loc) · 2.12 KB
/
adapter.spec.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
import { v4 as uuid } from "uuid";
import { PrismaAdapter } from "./adapter";
describe("Prisma Adapter", () => {
it("should upsert a model", async () => {
const adapter = new PrismaAdapter("ClientCredentials");
const id = uuid();
const data = { test: ["mostafa"] };
await adapter.upsert(id, data);
const result = await adapter.find(id);
expect(result).toEqual(data);
});
it("should upsert a model with user code", async () => {
const adapter = new PrismaAdapter("DeviceCode");
const id = uuid();
const keyId = uuid();
const data = { test: ["talaat"], userCode: keyId };
await adapter.upsert(id, data);
const result = await adapter.findByUserCode(keyId);
expect(result).toEqual(data);
});
it("should upsert a model with uid", async () => {
const adapter = new PrismaAdapter("Interaction");
const id = uuid();
const keyId = uuid();
const data = { test: ["abouzeid"], uid: keyId };
await adapter.upsert(id, data);
const result = await adapter.findByUid(keyId);
expect(result).toEqual(data);
});
it("should destroy a model", async () => {
const adapter = new PrismaAdapter("Interaction");
const id0 = uuid();
const id1 = uuid();
const data = { test: ["mostafatalaat770"] };
await adapter.upsert(id0, data);
await adapter.upsert(id1, data);
await adapter.destroy(id0);
const result0 = await adapter.find(id0);
const result1 = await adapter.find(id1);
expect(result0).toBeFalsy();
expect(result1).toEqual(data);
});
it("should revoke by grant id", async () => {
const adapter = new PrismaAdapter("AuthorizationCode");
const id = uuid();
const keyId = uuid();
const data = { test: ["mostabouzeid"], grantId: keyId };
await adapter.upsert(id, data);
await adapter.revokeByGrantId(keyId);
const result = await adapter.find(id);
expect(result).toBeFalsy();
});
it("should consume ", async () => {
const adapter = new PrismaAdapter("AccessToken");
const id = uuid();
const data = { test: ["test"] };
await adapter.upsert(id, data);
await adapter.consume(id);
const result = await adapter.find(id);
expect(result).toEqual({
...data,
consumed: true,
});
});
});