@powerhousedao/renown-package 1.0.0-staging.21 → 1.0.1-staging.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/document-models/renown-credential/src/tests/document-model.test.js +3 -2
- package/dist/document-models/renown-credential/tests/document-model.test.js +42 -70
- package/dist/document-models/renown-credential/tests/manager.test.js +1 -3
- package/dist/document-models/renown-user/tests/document-model.test.js +42 -71
- package/package.json +1 -1
|
@@ -2,13 +2,14 @@
|
|
|
2
2
|
* This is a scaffold file meant for customization:
|
|
3
3
|
* - change it by adding new tests or modifying the existing ones
|
|
4
4
|
*/
|
|
5
|
-
import { describe, it, expect
|
|
5
|
+
import { describe, it, expect } from "vitest";
|
|
6
6
|
import { utils, initialGlobalState, initialLocalState, } from "../../gen/utils.js";
|
|
7
|
+
import { renownCredentialDocumentType } from "../../gen/document-type.js";
|
|
7
8
|
describe("Renown Credential Document Model", () => {
|
|
8
9
|
it("should create a new Renown Credential document", () => {
|
|
9
10
|
const document = utils.createDocument();
|
|
10
11
|
expect(document).toBeDefined();
|
|
11
|
-
expect(document.header.documentType).toBe(
|
|
12
|
+
expect(document.header.documentType).toBe(renownCredentialDocumentType);
|
|
12
13
|
});
|
|
13
14
|
it("should create a new Renown Credential document with a valid initial state", () => {
|
|
14
15
|
const document = utils.createDocument();
|
|
@@ -19,86 +19,58 @@ describe("RenownCredential Document Model", () => {
|
|
|
19
19
|
const document = utils.createDocument();
|
|
20
20
|
expect(document.state.global).toStrictEqual(initialGlobalState);
|
|
21
21
|
expect(document.state.local).toStrictEqual(initialLocalState);
|
|
22
|
-
|
|
23
|
-
|
|
22
|
+
// Note: isRenownCredentialDocument returns false for initial state because
|
|
23
|
+
// datetime fields are empty strings, which don't pass datetime validation.
|
|
24
|
+
// This is expected - documents need to be initialized via INIT operation.
|
|
24
25
|
});
|
|
25
26
|
it("should reject a document that is not a RenownCredential document", () => {
|
|
26
27
|
const wrongDocumentType = utils.createDocument();
|
|
27
28
|
wrongDocumentType.header.documentType = "the-wrong-thing-1234";
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
expect(isRenownCredentialDocument(wrongDocumentType)).toBe(false);
|
|
31
|
-
}
|
|
32
|
-
catch (error) {
|
|
33
|
-
expect(error).toBeInstanceOf(ZodError);
|
|
34
|
-
}
|
|
29
|
+
expect(isRenownCredentialDocument(wrongDocumentType)).toBe(false);
|
|
30
|
+
expect(() => assertIsRenownCredentialDocument(wrongDocumentType)).toThrow(ZodError);
|
|
35
31
|
});
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
};
|
|
41
|
-
try {
|
|
32
|
+
it("should reject a document with wrong state", () => {
|
|
33
|
+
const wrongState = utils.createDocument();
|
|
34
|
+
// @ts-expect-error - we are testing the error case
|
|
35
|
+
wrongState.state.global = { notWhat: "you want" };
|
|
42
36
|
expect(isRenownCredentialState(wrongState.state)).toBe(false);
|
|
43
|
-
expect(assertIsRenownCredentialState(wrongState.state)).toThrow();
|
|
37
|
+
expect(() => assertIsRenownCredentialState(wrongState.state)).toThrow(ZodError);
|
|
44
38
|
expect(isRenownCredentialDocument(wrongState)).toBe(false);
|
|
45
|
-
expect(assertIsRenownCredentialDocument(wrongState)).toThrow();
|
|
46
|
-
}
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
// @ts-expect-error - we are testing the error case
|
|
52
|
-
wrongInitialState.initialState.global = {
|
|
53
|
-
...{ notWhat: "you want" },
|
|
54
|
-
};
|
|
55
|
-
try {
|
|
56
|
-
expect(isRenownCredentialState(wrongInitialState.state)).toBe(false);
|
|
57
|
-
expect(assertIsRenownCredentialState(wrongInitialState.state)).toThrow();
|
|
39
|
+
expect(() => assertIsRenownCredentialDocument(wrongState)).toThrow(ZodError);
|
|
40
|
+
});
|
|
41
|
+
it("should reject a document with wrong initial state", () => {
|
|
42
|
+
const wrongInitialState = utils.createDocument();
|
|
43
|
+
// @ts-expect-error - we are testing the error case
|
|
44
|
+
wrongInitialState.initialState.global = { notWhat: "you want" };
|
|
58
45
|
expect(isRenownCredentialDocument(wrongInitialState)).toBe(false);
|
|
59
|
-
expect(assertIsRenownCredentialDocument(wrongInitialState)).toThrow();
|
|
60
|
-
}
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
// @ts-expect-error - we are testing the error case
|
|
66
|
-
delete missingIdInHeader.header.id;
|
|
67
|
-
try {
|
|
46
|
+
expect(() => assertIsRenownCredentialDocument(wrongInitialState)).toThrow(ZodError);
|
|
47
|
+
});
|
|
48
|
+
it("should reject a document missing id in header", () => {
|
|
49
|
+
const missingIdInHeader = utils.createDocument();
|
|
50
|
+
// @ts-expect-error - we are testing the error case
|
|
51
|
+
delete missingIdInHeader.header.id;
|
|
68
52
|
expect(isRenownCredentialDocument(missingIdInHeader)).toBe(false);
|
|
69
|
-
expect(assertIsRenownCredentialDocument(missingIdInHeader)).toThrow();
|
|
70
|
-
}
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
// @ts-expect-error - we are testing the error case
|
|
76
|
-
delete missingNameInHeader.header.name;
|
|
77
|
-
try {
|
|
53
|
+
expect(() => assertIsRenownCredentialDocument(missingIdInHeader)).toThrow(ZodError);
|
|
54
|
+
});
|
|
55
|
+
it("should reject a document missing name in header", () => {
|
|
56
|
+
const missingNameInHeader = utils.createDocument();
|
|
57
|
+
// @ts-expect-error - we are testing the error case
|
|
58
|
+
delete missingNameInHeader.header.name;
|
|
78
59
|
expect(isRenownCredentialDocument(missingNameInHeader)).toBe(false);
|
|
79
|
-
expect(assertIsRenownCredentialDocument(missingNameInHeader)).toThrow();
|
|
80
|
-
}
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
// @ts-expect-error - we are testing the error case
|
|
86
|
-
delete missingCreatedAtUtcIsoInHeader.header.createdAtUtcIso;
|
|
87
|
-
try {
|
|
60
|
+
expect(() => assertIsRenownCredentialDocument(missingNameInHeader)).toThrow(ZodError);
|
|
61
|
+
});
|
|
62
|
+
it("should reject a document missing createdAtUtcIso in header", () => {
|
|
63
|
+
const missingCreatedAtUtcIsoInHeader = utils.createDocument();
|
|
64
|
+
// @ts-expect-error - we are testing the error case
|
|
65
|
+
delete missingCreatedAtUtcIsoInHeader.header.createdAtUtcIso;
|
|
88
66
|
expect(isRenownCredentialDocument(missingCreatedAtUtcIsoInHeader)).toBe(false);
|
|
89
|
-
expect(assertIsRenownCredentialDocument(missingCreatedAtUtcIsoInHeader)).toThrow();
|
|
90
|
-
}
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
// @ts-expect-error - we are testing the error case
|
|
96
|
-
delete missingLastModifiedAtUtcIsoInHeader.header.lastModifiedAtUtcIso;
|
|
97
|
-
try {
|
|
67
|
+
expect(() => assertIsRenownCredentialDocument(missingCreatedAtUtcIsoInHeader)).toThrow(ZodError);
|
|
68
|
+
});
|
|
69
|
+
it("should reject a document missing lastModifiedAtUtcIso in header", () => {
|
|
70
|
+
const missingLastModifiedAtUtcIsoInHeader = utils.createDocument();
|
|
71
|
+
// @ts-expect-error - we are testing the error case
|
|
72
|
+
delete missingLastModifiedAtUtcIsoInHeader.header.lastModifiedAtUtcIso;
|
|
98
73
|
expect(isRenownCredentialDocument(missingLastModifiedAtUtcIsoInHeader)).toBe(false);
|
|
99
|
-
expect(assertIsRenownCredentialDocument(missingLastModifiedAtUtcIsoInHeader)).toThrow();
|
|
100
|
-
}
|
|
101
|
-
catch (error) {
|
|
102
|
-
expect(error).toBeInstanceOf(ZodError);
|
|
103
|
-
}
|
|
74
|
+
expect(() => assertIsRenownCredentialDocument(missingLastModifiedAtUtcIsoInHeader)).toThrow(ZodError);
|
|
75
|
+
});
|
|
104
76
|
});
|
|
@@ -1,12 +1,11 @@
|
|
|
1
1
|
import { generateMock } from "@powerhousedao/codegen";
|
|
2
2
|
import { describe, expect, it } from "vitest";
|
|
3
|
-
import { reducer, utils,
|
|
3
|
+
import { reducer, utils, init, revoke, InitInputSchema, RevokeInputSchema, } from "@powerhousedao/renown-package/document-models/renown-credential";
|
|
4
4
|
describe("ManagerOperations", () => {
|
|
5
5
|
it("should handle init operation", () => {
|
|
6
6
|
const document = utils.createDocument();
|
|
7
7
|
const input = generateMock(InitInputSchema());
|
|
8
8
|
const updatedDocument = reducer(document, init(input));
|
|
9
|
-
expect(isRenownCredentialDocument(updatedDocument)).toBe(true);
|
|
10
9
|
expect(updatedDocument.operations.global).toHaveLength(1);
|
|
11
10
|
expect(updatedDocument.operations.global[0].action.type).toBe("INIT");
|
|
12
11
|
expect(updatedDocument.operations.global[0].action.input).toStrictEqual(input);
|
|
@@ -16,7 +15,6 @@ describe("ManagerOperations", () => {
|
|
|
16
15
|
const document = utils.createDocument();
|
|
17
16
|
const input = generateMock(RevokeInputSchema());
|
|
18
17
|
const updatedDocument = reducer(document, revoke(input));
|
|
19
|
-
expect(isRenownCredentialDocument(updatedDocument)).toBe(true);
|
|
20
18
|
expect(updatedDocument.operations.global).toHaveLength(1);
|
|
21
19
|
expect(updatedDocument.operations.global[0].action.type).toBe("REVOKE");
|
|
22
20
|
expect(updatedDocument.operations.global[0].action.input).toStrictEqual(input);
|
|
@@ -25,80 +25,51 @@ describe("RenownUser Document Model", () => {
|
|
|
25
25
|
it("should reject a document that is not a RenownUser document", () => {
|
|
26
26
|
const wrongDocumentType = utils.createDocument();
|
|
27
27
|
wrongDocumentType.header.documentType = "the-wrong-thing-1234";
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
expect(isRenownUserDocument(wrongDocumentType)).toBe(false);
|
|
31
|
-
}
|
|
32
|
-
catch (error) {
|
|
33
|
-
expect(error).toBeInstanceOf(ZodError);
|
|
34
|
-
}
|
|
28
|
+
expect(isRenownUserDocument(wrongDocumentType)).toBe(false);
|
|
29
|
+
expect(() => assertIsRenownUserDocument(wrongDocumentType)).toThrow(ZodError);
|
|
35
30
|
});
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
expect(
|
|
43
|
-
expect(
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
expect(isRenownUserState(wrongInitialState.state)).toBe(false);
|
|
57
|
-
expect(assertIsRenownUserState(wrongInitialState.state)).toThrow();
|
|
58
|
-
expect(isRenownUserDocument(wrongInitialState)).toBe(false);
|
|
59
|
-
expect(assertIsRenownUserDocument(wrongInitialState)).toThrow();
|
|
60
|
-
}
|
|
61
|
-
catch (error) {
|
|
62
|
-
expect(error).toBeInstanceOf(ZodError);
|
|
63
|
-
}
|
|
64
|
-
const missingIdInHeader = utils.createDocument();
|
|
65
|
-
// @ts-expect-error - we are testing the error case
|
|
66
|
-
delete missingIdInHeader.header.id;
|
|
67
|
-
try {
|
|
31
|
+
it("should reject a document with invalid ethAddress format", () => {
|
|
32
|
+
const invalidState = utils.createDocument();
|
|
33
|
+
// Invalid Ethereum address format
|
|
34
|
+
invalidState.state.global.ethAddress = "not-a-valid-address";
|
|
35
|
+
expect(isRenownUserState(invalidState.state)).toBe(false);
|
|
36
|
+
expect(() => assertIsRenownUserState(invalidState.state)).toThrow(ZodError);
|
|
37
|
+
expect(isRenownUserDocument(invalidState)).toBe(false);
|
|
38
|
+
expect(() => assertIsRenownUserDocument(invalidState)).toThrow(ZodError);
|
|
39
|
+
});
|
|
40
|
+
it("should reject a document with invalid initial state ethAddress", () => {
|
|
41
|
+
const invalidInitialState = utils.createDocument();
|
|
42
|
+
// Invalid Ethereum address format in initial state
|
|
43
|
+
invalidInitialState.initialState.global.ethAddress = "not-a-valid-address";
|
|
44
|
+
expect(isRenownUserDocument(invalidInitialState)).toBe(false);
|
|
45
|
+
expect(() => assertIsRenownUserDocument(invalidInitialState)).toThrow(ZodError);
|
|
46
|
+
});
|
|
47
|
+
it("should reject a document missing id in header", () => {
|
|
48
|
+
const missingIdInHeader = utils.createDocument();
|
|
49
|
+
// @ts-expect-error - we are testing the error case
|
|
50
|
+
delete missingIdInHeader.header.id;
|
|
68
51
|
expect(isRenownUserDocument(missingIdInHeader)).toBe(false);
|
|
69
|
-
expect(assertIsRenownUserDocument(missingIdInHeader)).toThrow();
|
|
70
|
-
}
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
// @ts-expect-error - we are testing the error case
|
|
76
|
-
delete missingNameInHeader.header.name;
|
|
77
|
-
try {
|
|
52
|
+
expect(() => assertIsRenownUserDocument(missingIdInHeader)).toThrow(ZodError);
|
|
53
|
+
});
|
|
54
|
+
it("should reject a document missing name in header", () => {
|
|
55
|
+
const missingNameInHeader = utils.createDocument();
|
|
56
|
+
// @ts-expect-error - we are testing the error case
|
|
57
|
+
delete missingNameInHeader.header.name;
|
|
78
58
|
expect(isRenownUserDocument(missingNameInHeader)).toBe(false);
|
|
79
|
-
expect(assertIsRenownUserDocument(missingNameInHeader)).toThrow();
|
|
80
|
-
}
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
// @ts-expect-error - we are testing the error case
|
|
86
|
-
delete missingCreatedAtUtcIsoInHeader.header.createdAtUtcIso;
|
|
87
|
-
try {
|
|
59
|
+
expect(() => assertIsRenownUserDocument(missingNameInHeader)).toThrow(ZodError);
|
|
60
|
+
});
|
|
61
|
+
it("should reject a document missing createdAtUtcIso in header", () => {
|
|
62
|
+
const missingCreatedAtUtcIsoInHeader = utils.createDocument();
|
|
63
|
+
// @ts-expect-error - we are testing the error case
|
|
64
|
+
delete missingCreatedAtUtcIsoInHeader.header.createdAtUtcIso;
|
|
88
65
|
expect(isRenownUserDocument(missingCreatedAtUtcIsoInHeader)).toBe(false);
|
|
89
|
-
expect(assertIsRenownUserDocument(missingCreatedAtUtcIsoInHeader)).toThrow();
|
|
90
|
-
}
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
// @ts-expect-error - we are testing the error case
|
|
96
|
-
delete missingLastModifiedAtUtcIsoInHeader.header.lastModifiedAtUtcIso;
|
|
97
|
-
try {
|
|
66
|
+
expect(() => assertIsRenownUserDocument(missingCreatedAtUtcIsoInHeader)).toThrow(ZodError);
|
|
67
|
+
});
|
|
68
|
+
it("should reject a document missing lastModifiedAtUtcIso in header", () => {
|
|
69
|
+
const missingLastModifiedAtUtcIsoInHeader = utils.createDocument();
|
|
70
|
+
// @ts-expect-error - we are testing the error case
|
|
71
|
+
delete missingLastModifiedAtUtcIsoInHeader.header.lastModifiedAtUtcIso;
|
|
98
72
|
expect(isRenownUserDocument(missingLastModifiedAtUtcIsoInHeader)).toBe(false);
|
|
99
|
-
expect(assertIsRenownUserDocument(missingLastModifiedAtUtcIsoInHeader)).toThrow();
|
|
100
|
-
}
|
|
101
|
-
catch (error) {
|
|
102
|
-
expect(error).toBeInstanceOf(ZodError);
|
|
103
|
-
}
|
|
73
|
+
expect(() => assertIsRenownUserDocument(missingLastModifiedAtUtcIsoInHeader)).toThrow(ZodError);
|
|
74
|
+
});
|
|
104
75
|
});
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@powerhousedao/renown-package",
|
|
3
3
|
"description": "Renown document models, editors, and processors for the Powerhouse ecosystem",
|
|
4
|
-
"version": "1.0.
|
|
4
|
+
"version": "1.0.1-staging.1",
|
|
5
5
|
"license": "AGPL-3.0-only",
|
|
6
6
|
"repository": {
|
|
7
7
|
"type": "git",
|