@sockethub/server 5.0.0-alpha.4 → 5.0.0-alpha.6
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/README.md +54 -60
- package/bin/sockethub +4 -3
- package/package.json +42 -54
- package/res/socket.io.js +4908 -0
- package/res/sockethub-client.js +602 -0
- package/res/sockethub-client.min.js +19 -0
- package/sockethub.config.example.json +2 -3
- package/src/bootstrap/init.d.ts +16 -13
- package/src/bootstrap/init.test.ts +211 -0
- package/src/bootstrap/init.ts +152 -76
- package/src/bootstrap/load-platforms.ts +151 -0
- package/src/config.test.ts +27 -22
- package/src/config.ts +82 -86
- package/src/defaults.json +24 -16
- package/src/index.ts +61 -22
- package/src/janitor.test.ts +191 -169
- package/src/janitor.ts +141 -118
- package/src/listener.ts +148 -58
- package/src/middleware/create-activity-object.test.ts +28 -8
- package/src/middleware/create-activity-object.ts +16 -10
- package/src/middleware/expand-activity-stream.test.data.ts +331 -345
- package/src/middleware/expand-activity-stream.test.ts +65 -66
- package/src/middleware/expand-activity-stream.ts +26 -21
- package/src/middleware/store-credentials.test.ts +74 -60
- package/src/middleware/store-credentials.ts +14 -8
- package/src/middleware/validate.test.data.ts +240 -242
- package/src/middleware/validate.test.ts +39 -78
- package/src/middleware/validate.ts +62 -36
- package/src/middleware.test.ts +168 -138
- package/src/middleware.ts +57 -55
- package/src/platform-instance.test.ts +508 -214
- package/src/platform-instance.ts +324 -231
- package/src/platform.test.ts +375 -0
- package/src/platform.ts +306 -117
- package/src/process-manager.ts +75 -51
- package/src/routes.test.ts +43 -89
- package/src/routes.ts +40 -78
- package/src/sentry.test.ts +106 -0
- package/src/sentry.ts +19 -0
- package/src/sockethub.ts +190 -129
- package/src/util.ts +5 -0
- package/coverage/tmp/coverage-39338-1663949520416-0.json +0 -1
- package/dist/bootstrap/init.d.ts +0 -18
- package/dist/bootstrap/init.js +0 -64
- package/dist/bootstrap/init.js.map +0 -1
- package/dist/bootstrap/platforms.js +0 -75
- package/dist/config.d.ts +0 -12
- package/dist/config.js +0 -107
- package/dist/config.js.map +0 -1
- package/dist/defaults.json +0 -28
- package/dist/index.d.ts +0 -1
- package/dist/index.js +0 -29
- package/dist/index.js.map +0 -1
- package/dist/janitor.d.ts +0 -30
- package/dist/janitor.js +0 -120
- package/dist/janitor.js.map +0 -1
- package/dist/listener.d.ts +0 -31
- package/dist/listener.js +0 -94
- package/dist/listener.js.map +0 -1
- package/dist/middleware/create-activity-object.d.ts +0 -8
- package/dist/middleware/create-activity-object.js +0 -19
- package/dist/middleware/create-activity-object.js.map +0 -1
- package/dist/middleware/expand-activity-stream.d.ts +0 -3
- package/dist/middleware/expand-activity-stream.js +0 -36
- package/dist/middleware/expand-activity-stream.js.map +0 -1
- package/dist/middleware/expand-activity-stream.test.data.d.ts +0 -480
- package/dist/middleware/expand-activity-stream.test.data.js +0 -360
- package/dist/middleware/expand-activity-stream.test.data.js.map +0 -1
- package/dist/middleware/store-credentials.d.ts +0 -3
- package/dist/middleware/store-credentials.js +0 -9
- package/dist/middleware/store-credentials.js.map +0 -1
- package/dist/middleware/validate.d.ts +0 -2
- package/dist/middleware/validate.js +0 -56
- package/dist/middleware/validate.js.map +0 -1
- package/dist/middleware/validate.test.data.d.ts +0 -532
- package/dist/middleware/validate.test.data.js +0 -263
- package/dist/middleware/validate.test.data.js.map +0 -1
- package/dist/middleware.d.ts +0 -21
- package/dist/middleware.js +0 -56
- package/dist/middleware.js.map +0 -1
- package/dist/platform-instance.d.ts +0 -78
- package/dist/platform-instance.js +0 -226
- package/dist/platform-instance.js.map +0 -1
- package/dist/platform.d.ts +0 -6
- package/dist/platform.js +0 -176
- package/dist/platform.js.map +0 -1
- package/dist/process-manager.d.ts +0 -11
- package/dist/process-manager.js +0 -82
- package/dist/process-manager.js.map +0 -1
- package/dist/routes.d.ts +0 -13
- package/dist/routes.js +0 -83
- package/dist/routes.js.map +0 -1
- package/dist/sockethub.d.ts +0 -18
- package/dist/sockethub.js +0 -112
- package/dist/sockethub.js.map +0 -1
- package/src/bootstrap/platforms.js +0 -75
- package/test/init-suite.js +0 -41
- package/test/sockethub-suite.js +0 -25
- package/tsconfig.json +0 -18
- package/views/examples/dummy.ejs +0 -95
- package/views/examples/feeds.ejs +0 -90
- package/views/examples/irc.ejs +0 -239
- package/views/examples/shared.js +0 -72
- package/views/examples/xmpp.ejs +0 -217
- package/views/index.ejs +0 -17
|
@@ -1,261 +1,259 @@
|
|
|
1
1
|
export default [
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
2
|
+
{
|
|
3
|
+
name: "mismatched types",
|
|
4
|
+
valid: false,
|
|
5
|
+
type: "credentials",
|
|
6
|
+
input: {
|
|
7
|
+
id: "blah",
|
|
8
|
+
type: "send",
|
|
9
|
+
context: "fakeplatform",
|
|
10
|
+
actor: {
|
|
11
|
+
id: "dood@irc.freenode.net",
|
|
12
|
+
type: "person",
|
|
13
|
+
name: "dood",
|
|
14
|
+
},
|
|
15
|
+
target: {
|
|
16
|
+
id: "irc.freenode.net/service",
|
|
17
|
+
type: "person",
|
|
18
|
+
name: "service",
|
|
19
|
+
},
|
|
20
|
+
object: {
|
|
21
|
+
type: "credentials",
|
|
22
|
+
user: "foo",
|
|
23
|
+
pass: "bar",
|
|
24
|
+
},
|
|
25
|
+
},
|
|
26
|
+
error: "Error: credential activity streams must have credentials set as type",
|
|
25
27
|
},
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
28
|
+
{
|
|
29
|
+
name: "basic",
|
|
30
|
+
valid: true,
|
|
31
|
+
type: "credentials",
|
|
32
|
+
input: {
|
|
33
|
+
id: "blah",
|
|
34
|
+
type: "credentials",
|
|
35
|
+
context: "fakeplatform",
|
|
36
|
+
actor: {
|
|
37
|
+
id: "dood@irc.freenode.net",
|
|
38
|
+
type: "person",
|
|
39
|
+
name: "dood",
|
|
40
|
+
},
|
|
41
|
+
object: {
|
|
42
|
+
type: "credentials",
|
|
43
|
+
user: "foo",
|
|
44
|
+
pass: "bar",
|
|
45
|
+
},
|
|
46
|
+
},
|
|
47
|
+
output: "same",
|
|
46
48
|
},
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
49
|
+
{
|
|
50
|
+
name: "no type specified",
|
|
51
|
+
valid: false,
|
|
52
|
+
type: "credentials",
|
|
53
|
+
input: {
|
|
54
|
+
actor: "hyper_rau@localhost",
|
|
55
|
+
context: "fakeplatform",
|
|
56
|
+
object: {
|
|
57
|
+
username: "hyper_rau",
|
|
58
|
+
password: "123",
|
|
59
|
+
server: "localhost",
|
|
60
|
+
port: 5222,
|
|
61
|
+
resource: "laptop",
|
|
62
|
+
},
|
|
63
|
+
},
|
|
64
|
+
error: "Error: credential activity streams must have credentials set as type",
|
|
63
65
|
},
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
66
|
+
{
|
|
67
|
+
name: "basic person",
|
|
68
|
+
type: "activity-object",
|
|
69
|
+
valid: true,
|
|
70
|
+
input: {
|
|
71
|
+
id: "blah",
|
|
72
|
+
type: "person",
|
|
73
|
+
name: "dood",
|
|
74
|
+
},
|
|
75
|
+
output: "same",
|
|
74
76
|
},
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
"am",
|
|
88
|
-
"extras"
|
|
89
|
-
]
|
|
77
|
+
{
|
|
78
|
+
name: "person with extras",
|
|
79
|
+
valid: true,
|
|
80
|
+
type: "activity-object",
|
|
81
|
+
input: {
|
|
82
|
+
id: "blah",
|
|
83
|
+
type: "person",
|
|
84
|
+
name: "bob",
|
|
85
|
+
hello: "there",
|
|
86
|
+
i: ["am", "extras"],
|
|
87
|
+
},
|
|
88
|
+
output: "same",
|
|
90
89
|
},
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
90
|
+
{
|
|
91
|
+
name: "alone credentials (as activity-object)",
|
|
92
|
+
valid: false,
|
|
93
|
+
type: "activity-object",
|
|
94
|
+
input: {
|
|
95
|
+
type: "credentials",
|
|
96
|
+
nick: "sh-9K3Vk",
|
|
97
|
+
port: 6667,
|
|
98
|
+
secure: false,
|
|
99
|
+
server: "irc.freenode.net",
|
|
100
|
+
},
|
|
101
|
+
error:
|
|
102
|
+
"Error: /object: must match exactly one schema in oneOf: " +
|
|
103
|
+
"credentials, feed, message, me, person, room, service, website, " +
|
|
104
|
+
"attendance, presence, relationship, topic, address",
|
|
103
105
|
},
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
"port":6667,
|
|
117
|
-
"secure":false,
|
|
118
|
-
"server":"irc.freenode.net"
|
|
106
|
+
{
|
|
107
|
+
name: "alone credentials (as credentials)",
|
|
108
|
+
valid: false,
|
|
109
|
+
type: "credentials",
|
|
110
|
+
input: {
|
|
111
|
+
type: "credentials",
|
|
112
|
+
nick: "sh-9K3Vk",
|
|
113
|
+
port: 6667,
|
|
114
|
+
secure: false,
|
|
115
|
+
server: "irc.freenode.net",
|
|
116
|
+
},
|
|
117
|
+
error: "Error: platform context undefined not registered with this Sockethub instance.",
|
|
119
118
|
},
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
119
|
+
{
|
|
120
|
+
name: "new person",
|
|
121
|
+
valid: true,
|
|
122
|
+
type: "activity-object",
|
|
123
|
+
input: {
|
|
124
|
+
id: "sh-9K3Vk@irc.freenode.net",
|
|
125
|
+
type: "person",
|
|
126
|
+
name: "sh-9K3Vk",
|
|
127
|
+
image: {
|
|
128
|
+
height: 250,
|
|
129
|
+
mediaType: "image/jpeg",
|
|
130
|
+
url: "https://example.org/image.jpg",
|
|
131
|
+
width: 250,
|
|
132
|
+
},
|
|
133
|
+
url: "https://sockethub.org",
|
|
134
|
+
},
|
|
135
|
+
output: "same",
|
|
137
136
|
},
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
137
|
+
{
|
|
138
|
+
name: "new person",
|
|
139
|
+
valid: true,
|
|
140
|
+
type: "activity-object",
|
|
141
|
+
input: {
|
|
142
|
+
id: "irc://sh-9K3Vk@irc.freenode.net",
|
|
143
|
+
type: "person",
|
|
144
|
+
name: "sh-9K3Vk",
|
|
145
|
+
url: "https://sockethub.org",
|
|
146
|
+
},
|
|
147
|
+
output: "same",
|
|
149
148
|
},
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
149
|
+
{
|
|
150
|
+
name: "bad parent object",
|
|
151
|
+
valid: false,
|
|
152
|
+
type: "activity-stream",
|
|
153
|
+
input: {
|
|
154
|
+
string: "this is a string",
|
|
155
|
+
array: [
|
|
156
|
+
"this",
|
|
157
|
+
"is",
|
|
158
|
+
{
|
|
159
|
+
an: "array",
|
|
160
|
+
},
|
|
161
|
+
],
|
|
162
|
+
as: {
|
|
163
|
+
id: "blah",
|
|
164
|
+
type: "send",
|
|
165
|
+
context: "hello",
|
|
166
|
+
actor: {
|
|
167
|
+
name: "dood",
|
|
168
|
+
},
|
|
169
|
+
target: {
|
|
170
|
+
type: "person",
|
|
171
|
+
name: "bob",
|
|
172
|
+
},
|
|
173
|
+
object: {
|
|
174
|
+
type: "credentials",
|
|
175
|
+
},
|
|
176
|
+
},
|
|
177
|
+
noId: {
|
|
178
|
+
name: "dood",
|
|
179
|
+
},
|
|
180
|
+
noId2: {
|
|
181
|
+
type: "person",
|
|
182
|
+
name: "bob",
|
|
183
|
+
},
|
|
184
|
+
noDisplayName: {
|
|
185
|
+
id: "larg",
|
|
186
|
+
},
|
|
171
187
|
},
|
|
172
|
-
"
|
|
173
|
-
|
|
174
|
-
|
|
188
|
+
error: "Error: platform context undefined not registered with this Sockethub instance.",
|
|
189
|
+
},
|
|
190
|
+
{
|
|
191
|
+
name: "unexpected AS",
|
|
192
|
+
valid: false,
|
|
193
|
+
type: "message",
|
|
194
|
+
input: {
|
|
195
|
+
actor: "irc://uuu@localhost",
|
|
196
|
+
type: "join",
|
|
197
|
+
context: "fakeplatform",
|
|
198
|
+
target: "irc://irc.dooder.net/a-room",
|
|
175
199
|
},
|
|
176
|
-
"object"
|
|
177
|
-
"type":"credentials"
|
|
178
|
-
}
|
|
179
|
-
},
|
|
180
|
-
"noId":{
|
|
181
|
-
"name":"dood"
|
|
182
|
-
},
|
|
183
|
-
"noId2":{
|
|
184
|
-
"type":"person",
|
|
185
|
-
"name":"bob"
|
|
186
|
-
},
|
|
187
|
-
"noDisplayName":{
|
|
188
|
-
"id":"larg"
|
|
189
|
-
}
|
|
200
|
+
error: "Error: [fakeplatform] /actor: must be object",
|
|
190
201
|
},
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
"target":"irc://irc.dooder.net/a-room"
|
|
202
|
+
{
|
|
203
|
+
name: "missing type property",
|
|
204
|
+
valid: false,
|
|
205
|
+
type: "message",
|
|
206
|
+
input: {
|
|
207
|
+
actor: { id: "irc://uuu@localhost", type: "person" },
|
|
208
|
+
context: "fakeplatform",
|
|
209
|
+
target: { id: "irc://irc.dooder.net/a-room", type: "room" },
|
|
210
|
+
},
|
|
211
|
+
error: "Error: [fakeplatform] activity stream: must have required property 'type'",
|
|
202
212
|
},
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
+
{
|
|
214
|
+
name: "invalid context property",
|
|
215
|
+
valid: false,
|
|
216
|
+
type: "message",
|
|
217
|
+
input: {
|
|
218
|
+
actor: { id: "irc://uuu@localhost", type: "person" },
|
|
219
|
+
type: "foo",
|
|
220
|
+
context: "foobar111",
|
|
221
|
+
target: { id: "irc://irc.dooder.net/a-room", type: "room" },
|
|
222
|
+
},
|
|
223
|
+
error: "Error: platform context foobar111 not registered with this Sockethub instance.",
|
|
213
224
|
},
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
"target": { "id": "irc://irc.dooder.net/a-room", "type": "room" }
|
|
225
|
+
{
|
|
226
|
+
name: "missing actor property",
|
|
227
|
+
valid: false,
|
|
228
|
+
type: "message",
|
|
229
|
+
input: {
|
|
230
|
+
type: "foo",
|
|
231
|
+
context: "fakeplatform",
|
|
232
|
+
target: { id: "irc://irc.dooder.net/a-room", type: "room" },
|
|
233
|
+
},
|
|
234
|
+
error: "Error: [fakeplatform] activity stream: must have required property 'actor'",
|
|
225
235
|
},
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
"target": { "id": "irc://irc.dooder.net/a-room", "type": "room" }
|
|
236
|
+
{
|
|
237
|
+
name: "traditional message",
|
|
238
|
+
valid: true,
|
|
239
|
+
type: "message",
|
|
240
|
+
input: {
|
|
241
|
+
type: "echo",
|
|
242
|
+
context: "fakeplatform",
|
|
243
|
+
actor: { id: "irc://uuu@localhost", type: "person" },
|
|
244
|
+
},
|
|
236
245
|
},
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
{
|
|
250
|
-
"name":"message with wrong type",
|
|
251
|
-
"valid":false,
|
|
252
|
-
"type":"message",
|
|
253
|
-
"input":{
|
|
254
|
-
"type": "foorg",
|
|
255
|
-
"context": "fake",
|
|
256
|
-
"actor": { "id": "irc://uuu@localhost", "type": "person" }
|
|
246
|
+
{
|
|
247
|
+
name: "message with wrong type",
|
|
248
|
+
valid: false,
|
|
249
|
+
type: "message",
|
|
250
|
+
input: {
|
|
251
|
+
type: "foorg",
|
|
252
|
+
context: "fakeplatform",
|
|
253
|
+
actor: { id: "irc://uuu@localhost", type: "person" },
|
|
254
|
+
},
|
|
255
|
+
error:
|
|
256
|
+
"Error: platform type foorg not supported by fakeplatform platform. " +
|
|
257
|
+
"(types: credentials, echo, fail)",
|
|
257
258
|
},
|
|
258
|
-
"error": "Error: platform type foorg not supported by fake platform. " +
|
|
259
|
-
"(types: credentials, echo, fail)"
|
|
260
|
-
}
|
|
261
259
|
];
|
|
@@ -1,83 +1,44 @@
|
|
|
1
|
-
import { expect } from
|
|
2
|
-
import
|
|
1
|
+
import { describe, expect, it } from "bun:test";
|
|
2
|
+
import type { ActivityStream } from "@sockethub/schemas";
|
|
3
|
+
import getInitObject from "../bootstrap/init.js";
|
|
4
|
+
import { initMockFakePlatform } from "../bootstrap/init.test.js";
|
|
5
|
+
import validate from "./validate.js";
|
|
6
|
+
import asObjects from "./validate.test.data.js";
|
|
3
7
|
|
|
4
|
-
|
|
5
|
-
|
|
8
|
+
describe("Middleware: Validate", async () => {
|
|
9
|
+
const loadInitMock = await initMockFakePlatform("fakeplatform");
|
|
10
|
+
const initObj = await getInitObject(loadInitMock);
|
|
6
11
|
|
|
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
|
-
const validateMod = proxyquire('./validate', {
|
|
38
|
-
'../bootstrap/init': {
|
|
39
|
-
platforms: platforms
|
|
40
|
-
}
|
|
41
|
-
});
|
|
42
|
-
const validate = validateMod.default;
|
|
43
|
-
|
|
44
|
-
import asObjects from "./validate.test.data";
|
|
45
|
-
|
|
46
|
-
describe('platformLoad', () => {
|
|
47
|
-
it('loads all platforms', () => {
|
|
48
|
-
const expectedPlatforms = ['fake'];
|
|
49
|
-
expect(platforms.size).to.equal(expectedPlatforms.length);
|
|
50
|
-
for (let platform of expectedPlatforms) {
|
|
51
|
-
expect(platforms.has(platform)).to.be.true;
|
|
52
|
-
}
|
|
53
|
-
});
|
|
54
|
-
});
|
|
55
|
-
|
|
56
|
-
describe('Middleware: Validate', () => {
|
|
57
|
-
|
|
58
|
-
describe('AS object validations', () => {
|
|
59
|
-
asObjects.forEach((obj) => {
|
|
60
|
-
it(`${obj.type}: ${obj.name}, should ${obj.valid ? 'pass' : 'fail'}`, (done) => {
|
|
61
|
-
// @ts-ignore
|
|
62
|
-
validate(obj.type, 'tests')(obj.input, (msg) => {
|
|
63
|
-
if (obj.output) {
|
|
64
|
-
if (obj.output === 'same') {
|
|
65
|
-
expect(msg).to.eql(obj.input);
|
|
66
|
-
} else {
|
|
67
|
-
expect(msg).to.eql(obj.output);
|
|
68
|
-
}
|
|
69
|
-
}
|
|
70
|
-
if (obj.valid) {
|
|
71
|
-
expect(msg).to.not.be.instanceof(Error);
|
|
72
|
-
} else {
|
|
73
|
-
expect(msg).to.be.instanceof(Error);
|
|
74
|
-
if (obj.error) {
|
|
75
|
-
expect(msg.toString()).to.equal(obj.error);
|
|
76
|
-
}
|
|
77
|
-
}
|
|
78
|
-
done();
|
|
12
|
+
describe("AS object validations", () => {
|
|
13
|
+
asObjects.forEach((obj) => {
|
|
14
|
+
it(`${obj.type}: ${obj.name}, should ${
|
|
15
|
+
obj.valid ? "pass" : "fail"
|
|
16
|
+
}`, (done) => {
|
|
17
|
+
validate(
|
|
18
|
+
obj.type,
|
|
19
|
+
"tests",
|
|
20
|
+
initObj,
|
|
21
|
+
)(obj.input as ActivityStream, (msg) => {
|
|
22
|
+
if (obj.output) {
|
|
23
|
+
if (obj.output === "same") {
|
|
24
|
+
// @ts-ignore
|
|
25
|
+
expect(msg).toEqual(obj.input);
|
|
26
|
+
} else {
|
|
27
|
+
// @ts-ignore
|
|
28
|
+
expect(msg).toEqual(obj.output);
|
|
29
|
+
}
|
|
30
|
+
}
|
|
31
|
+
if (obj.valid) {
|
|
32
|
+
expect(msg).not.toBeInstanceOf(Error);
|
|
33
|
+
} else {
|
|
34
|
+
expect(msg).toBeInstanceOf(Error);
|
|
35
|
+
if (obj.error) {
|
|
36
|
+
expect(msg.toString()).toEqual(obj.error);
|
|
37
|
+
}
|
|
38
|
+
}
|
|
39
|
+
done();
|
|
40
|
+
});
|
|
41
|
+
});
|
|
79
42
|
});
|
|
80
|
-
});
|
|
81
43
|
});
|
|
82
|
-
});
|
|
83
44
|
});
|