@rtsdk/topia 0.0.18 → 0.0.20
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 +138 -5
- package/dist/index.js +1 -1
- package/dist/src/controllers/Asset.js +2 -0
- package/dist/src/controllers/DroppedAsset.js +2 -0
- package/dist/src/controllers/SDKController.js +2 -0
- package/dist/src/controllers/Topia.js +2 -0
- package/dist/src/controllers/User.js +2 -0
- package/dist/src/controllers/Visitor.js +2 -0
- package/dist/src/controllers/World.js +2 -0
- package/dist/src/index.js +10 -0
- package/dist/src/utils/getErrorResponse.js +10 -8
- package/package.json +2 -2
- package/dist/__mocks__/assets.js +0 -241
- package/dist/__mocks__/index.js +0 -4
- package/dist/__mocks__/scenes.js +0 -104
- package/dist/__mocks__/visitors.js +0 -83
- package/dist/__mocks__/worlds.js +0 -52
- package/dist/controllers/Asset.js +0 -31
- package/dist/controllers/DroppedAsset.js +0 -335
- package/dist/controllers/SDKController.js +0 -36
- package/dist/controllers/Topia.js +0 -32
- package/dist/controllers/User.js +0 -106
- package/dist/controllers/Visitor.js +0 -55
- package/dist/controllers/World.js +0 -328
- package/dist/controllers/__tests__/asset.test.js +0 -37
- package/dist/controllers/__tests__/droppedAsset.test.js +0 -98
- package/dist/controllers/__tests__/user.test.js +0 -50
- package/dist/controllers/__tests__/visitor.test.js +0 -41
- package/dist/controllers/__tests__/world.test.js +0 -77
- package/dist/controllers/index.js +0 -7
- package/dist/factories/AssetFactory.js +0 -11
- package/dist/factories/DroppedAssetFactory.js +0 -26
- package/dist/factories/UserFactory.js +0 -10
- package/dist/factories/VisitorFactory.js +0 -10
- package/dist/factories/WorldFactory.js +0 -10
- package/dist/factories/index.js +0 -5
- package/dist/interfaces/AssetInterfaces.js +0 -1
- package/dist/interfaces/DroppedAssetInterfaces.js +0 -1
- package/dist/interfaces/SDKInterfaces.js +0 -1
- package/dist/interfaces/TopiaInterfaces.js +0 -1
- package/dist/interfaces/UserInterfaces.js +0 -1
- package/dist/interfaces/VisitorInterfaces.js +0 -1
- package/dist/interfaces/WorldInterfaces.js +0 -1
- package/dist/interfaces/index.js +0 -7
- package/dist/src/utils/getErrorMessage.js +0 -5
- package/dist/src/utils/getSuccessResponse.js +0 -3
- package/dist/types/DroppedAssetTypes.js +0 -12
- package/dist/types/InteractiveCredentialsTypes.js +0 -1
- package/dist/types/OptionsTypes.js +0 -1
- package/dist/types/VisitorTypes.js +0 -1
- package/dist/types/index.js +0 -3
- package/dist/utils/__tests__/removeUndefined.test.js +0 -10
- package/dist/utils/__tests__/scatterVisitors.test.js +0 -11
- package/dist/utils/getErrorMessage.js +0 -7
- package/dist/utils/index.js +0 -4
- package/dist/utils/publicAPI.js +0 -13
- package/dist/utils/removeUndefined.js +0 -11
- package/dist/utils/scatterVisitors.js +0 -8
|
@@ -1,328 +0,0 @@
|
|
|
1
|
-
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
2
|
-
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
3
|
-
return new (P || (P = Promise))(function (resolve, reject) {
|
|
4
|
-
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
5
|
-
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
6
|
-
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
7
|
-
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
8
|
-
});
|
|
9
|
-
};
|
|
10
|
-
var __classPrivateFieldSet = (this && this.__classPrivateFieldSet) || function (receiver, state, value, kind, f) {
|
|
11
|
-
if (kind === "m") throw new TypeError("Private method is not writable");
|
|
12
|
-
if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a setter");
|
|
13
|
-
if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver)) throw new TypeError("Cannot write private member to an object whose class did not declare it");
|
|
14
|
-
return (kind === "a" ? f.call(receiver, value) : f ? f.value = value : state.set(receiver, value)), value;
|
|
15
|
-
};
|
|
16
|
-
var __classPrivateFieldGet = (this && this.__classPrivateFieldGet) || function (receiver, state, kind, f) {
|
|
17
|
-
if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a getter");
|
|
18
|
-
if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver)) throw new TypeError("Cannot read private member from an object whose class did not declare it");
|
|
19
|
-
return kind === "m" ? f : kind === "a" ? f.call(receiver) : f ? f.value : state.get(receiver);
|
|
20
|
-
};
|
|
21
|
-
var _World_droppedAssetsMap, _World_visitorsMap;
|
|
22
|
-
// controllers
|
|
23
|
-
import { DroppedAsset } from "controllers/DroppedAsset";
|
|
24
|
-
import { SDKController } from "controllers/SDKController";
|
|
25
|
-
import { Visitor } from "controllers/Visitor";
|
|
26
|
-
// utils
|
|
27
|
-
import { getErrorMessage, removeUndefined, scatterVisitors } from "utils";
|
|
28
|
-
/**
|
|
29
|
-
* Create an instance of World class with a given apiKey and optional arguments.
|
|
30
|
-
*
|
|
31
|
-
* ```ts
|
|
32
|
-
* await new World({ urlSlug: "magic" });
|
|
33
|
-
* ```
|
|
34
|
-
*/
|
|
35
|
-
export class World extends SDKController {
|
|
36
|
-
constructor(topia, urlSlug, options = { args: {}, creds: {} }) {
|
|
37
|
-
super(topia, options.creds);
|
|
38
|
-
_World_droppedAssetsMap.set(this, void 0);
|
|
39
|
-
_World_visitorsMap.set(this, void 0);
|
|
40
|
-
Object.assign(this, options.args);
|
|
41
|
-
__classPrivateFieldSet(this, _World_droppedAssetsMap, {}, "f");
|
|
42
|
-
__classPrivateFieldSet(this, _World_visitorsMap, {}, "f");
|
|
43
|
-
this.urlSlug = urlSlug;
|
|
44
|
-
}
|
|
45
|
-
get droppedAssets() {
|
|
46
|
-
return __classPrivateFieldGet(this, _World_droppedAssetsMap, "f");
|
|
47
|
-
}
|
|
48
|
-
get visitors() {
|
|
49
|
-
return __classPrivateFieldGet(this, _World_visitorsMap, "f");
|
|
50
|
-
}
|
|
51
|
-
/**
|
|
52
|
-
* @summary
|
|
53
|
-
* Retrieves details of a world.
|
|
54
|
-
*
|
|
55
|
-
* @usage
|
|
56
|
-
* ```ts
|
|
57
|
-
* await world.fetchDetails();
|
|
58
|
-
* const { name } = world;
|
|
59
|
-
* ```
|
|
60
|
-
*/
|
|
61
|
-
// world details
|
|
62
|
-
fetchDetails() {
|
|
63
|
-
return new Promise((resolve, reject) => {
|
|
64
|
-
this.topia.axios
|
|
65
|
-
.get(`/world/${this.urlSlug}/world-details`, this.requestOptions)
|
|
66
|
-
.then((response) => {
|
|
67
|
-
Object.assign(this, response.data);
|
|
68
|
-
resolve("Success!");
|
|
69
|
-
})
|
|
70
|
-
.catch((error) => {
|
|
71
|
-
reject(new Error(getErrorMessage(error)));
|
|
72
|
-
});
|
|
73
|
-
});
|
|
74
|
-
}
|
|
75
|
-
/**
|
|
76
|
-
* @summary
|
|
77
|
-
* Update details of a world.
|
|
78
|
-
*
|
|
79
|
-
* @usage
|
|
80
|
-
* ```ts
|
|
81
|
-
* await world.updateDetails({
|
|
82
|
-
* controls: {
|
|
83
|
-
* allowMuteAll: true,
|
|
84
|
-
* disableHideVideo: true,
|
|
85
|
-
* isMobileDisabled: false,
|
|
86
|
-
* isShowingCurrentGuests: false,
|
|
87
|
-
* },
|
|
88
|
-
* description: 'Welcome to my world.',
|
|
89
|
-
* forceAuthOnLogin: false,
|
|
90
|
-
* height: 2000,
|
|
91
|
-
* name: 'Example',
|
|
92
|
-
* spawnPosition: { x: 100, y: 100 },
|
|
93
|
-
* width: 2000
|
|
94
|
-
* });
|
|
95
|
-
* ```
|
|
96
|
-
*/
|
|
97
|
-
updateDetails({ controls, description, forceAuthOnLogin, height, name, spawnPosition, width, }) {
|
|
98
|
-
const payload = {
|
|
99
|
-
controls,
|
|
100
|
-
description,
|
|
101
|
-
forceAuthOnLogin,
|
|
102
|
-
height,
|
|
103
|
-
name,
|
|
104
|
-
spawnPosition,
|
|
105
|
-
width,
|
|
106
|
-
};
|
|
107
|
-
return new Promise((resolve, reject) => {
|
|
108
|
-
this.topia.axios
|
|
109
|
-
.put(`/world/${this.urlSlug}/world-details`, payload, this.requestOptions)
|
|
110
|
-
.then(() => {
|
|
111
|
-
const cleanPayload = removeUndefined(payload);
|
|
112
|
-
Object.assign(this, cleanPayload);
|
|
113
|
-
resolve("Success!");
|
|
114
|
-
})
|
|
115
|
-
.catch((error) => {
|
|
116
|
-
reject(new Error(getErrorMessage(error)));
|
|
117
|
-
});
|
|
118
|
-
});
|
|
119
|
-
}
|
|
120
|
-
// visitors
|
|
121
|
-
fetchVisitors() {
|
|
122
|
-
return new Promise((resolve, reject) => {
|
|
123
|
-
this.topia.axios
|
|
124
|
-
.get(`/world/${this.urlSlug}/visitors`, this.requestOptions)
|
|
125
|
-
.then((response) => {
|
|
126
|
-
// create temp map and then update private property only once
|
|
127
|
-
const tempVisitorsMap = {};
|
|
128
|
-
for (const id in response.data) {
|
|
129
|
-
tempVisitorsMap[id] = new Visitor(this.topia, response.data[id].playerId, this.urlSlug, {
|
|
130
|
-
args: response.data[id],
|
|
131
|
-
});
|
|
132
|
-
}
|
|
133
|
-
__classPrivateFieldSet(this, _World_visitorsMap, tempVisitorsMap, "f");
|
|
134
|
-
resolve("Success!");
|
|
135
|
-
})
|
|
136
|
-
.catch((error) => {
|
|
137
|
-
reject(new Error(getErrorMessage(error)));
|
|
138
|
-
});
|
|
139
|
-
});
|
|
140
|
-
}
|
|
141
|
-
/**
|
|
142
|
-
* @summary
|
|
143
|
-
* Retrieve all visitors currently in a world.
|
|
144
|
-
*
|
|
145
|
-
* @usage
|
|
146
|
-
* ```ts
|
|
147
|
-
* const visitors = await world.currentVisitors();
|
|
148
|
-
* ```
|
|
149
|
-
*/
|
|
150
|
-
currentVisitors() {
|
|
151
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
152
|
-
try {
|
|
153
|
-
yield this.fetchVisitors();
|
|
154
|
-
return this.visitors;
|
|
155
|
-
}
|
|
156
|
-
catch (error) {
|
|
157
|
-
return error;
|
|
158
|
-
}
|
|
159
|
-
});
|
|
160
|
-
}
|
|
161
|
-
/**
|
|
162
|
-
* @summary
|
|
163
|
-
* Move all visitors currently in a world to a single set of coordinates.
|
|
164
|
-
* Optionally refetch visitors, teleport or walk visitors to new location,
|
|
165
|
-
* and scatter visitors by any number so that they don't all move to the exact same location.
|
|
166
|
-
*
|
|
167
|
-
* @usage
|
|
168
|
-
* ```ts
|
|
169
|
-
* await world.moveAllVisitors({
|
|
170
|
-
* shouldFetchVisitors: true,
|
|
171
|
-
* shouldTeleportVisitors: true,
|
|
172
|
-
* scatterVisitorsBy: 40,
|
|
173
|
-
* x: 100,
|
|
174
|
-
* y: 100,
|
|
175
|
-
* });
|
|
176
|
-
* ```
|
|
177
|
-
*
|
|
178
|
-
* @result
|
|
179
|
-
* Updates each Visitor instance and world.visitors map.
|
|
180
|
-
*/
|
|
181
|
-
moveAllVisitors({ shouldFetchVisitors = true, shouldTeleportVisitors = true, scatterVisitorsBy = 0, x, y, }) {
|
|
182
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
183
|
-
if (shouldFetchVisitors)
|
|
184
|
-
yield this.fetchVisitors();
|
|
185
|
-
const allPromises = [];
|
|
186
|
-
if (!this.visitors)
|
|
187
|
-
return;
|
|
188
|
-
const objectKeys = Object.keys(this.visitors);
|
|
189
|
-
objectKeys.forEach((key) => allPromises.push(__classPrivateFieldGet(this, _World_visitorsMap, "f")[key].moveVisitor({
|
|
190
|
-
shouldTeleportVisitor: shouldTeleportVisitors,
|
|
191
|
-
x: scatterVisitors(x, scatterVisitorsBy),
|
|
192
|
-
y: scatterVisitors(y, scatterVisitorsBy),
|
|
193
|
-
})));
|
|
194
|
-
const outcomes = yield Promise.allSettled(allPromises);
|
|
195
|
-
return outcomes;
|
|
196
|
-
});
|
|
197
|
-
}
|
|
198
|
-
/**
|
|
199
|
-
* @summary
|
|
200
|
-
* Teleport or walk a list of visitors currently in a world to various coordinates.
|
|
201
|
-
*
|
|
202
|
-
* @usage
|
|
203
|
-
* ```ts
|
|
204
|
-
* const visitorsToMove = [
|
|
205
|
-
* {
|
|
206
|
-
* visitorObj: world.visitors["1"],
|
|
207
|
-
* shouldTeleportVisitor: true,
|
|
208
|
-
* x: 100,
|
|
209
|
-
* y: 100
|
|
210
|
-
* }, {
|
|
211
|
-
* visitorObj: world.visitors["2"],
|
|
212
|
-
* shouldTeleportVisitor: false,
|
|
213
|
-
* x: 100,
|
|
214
|
-
* y: 100
|
|
215
|
-
* }
|
|
216
|
-
* ];
|
|
217
|
-
* await world.moveVisitors(visitorsToMove);
|
|
218
|
-
* ```
|
|
219
|
-
*
|
|
220
|
-
* @result
|
|
221
|
-
* Updates each Visitor instance and world.visitors map.
|
|
222
|
-
*/
|
|
223
|
-
moveVisitors(visitorsToMove) {
|
|
224
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
225
|
-
const allPromises = [];
|
|
226
|
-
visitorsToMove.forEach((v) => {
|
|
227
|
-
allPromises.push(v.visitorObj.moveVisitor({ shouldTeleportVisitor: v.shouldTeleportVisitor, x: v.x, y: v.y }));
|
|
228
|
-
});
|
|
229
|
-
const outcomes = yield Promise.allSettled(allPromises);
|
|
230
|
-
return outcomes;
|
|
231
|
-
});
|
|
232
|
-
}
|
|
233
|
-
/**
|
|
234
|
-
* @summary
|
|
235
|
-
* Retrieve all assets dropped in a world.
|
|
236
|
-
*
|
|
237
|
-
* @usage
|
|
238
|
-
* ```ts
|
|
239
|
-
* await world.fetchDroppedAssets();
|
|
240
|
-
* const assets = world.droppedAssets;
|
|
241
|
-
* ```
|
|
242
|
-
*/
|
|
243
|
-
// dropped assets
|
|
244
|
-
fetchDroppedAssets() {
|
|
245
|
-
return new Promise((resolve, reject) => {
|
|
246
|
-
this.topia.axios
|
|
247
|
-
.get(`/world/${this.urlSlug}/assets`, this.requestOptions)
|
|
248
|
-
.then((response) => {
|
|
249
|
-
// create temp map and then update private property only once
|
|
250
|
-
const tempDroppedAssetsMap = {};
|
|
251
|
-
for (const index in response.data) {
|
|
252
|
-
// tempDroppedAssetsMap[id] = createDroppedAsset(this.apiKey, response.data[id], this.urlSlug);
|
|
253
|
-
tempDroppedAssetsMap[index] = new DroppedAsset(this.topia, response.data[index].id, this.urlSlug, {
|
|
254
|
-
args: response.data[index],
|
|
255
|
-
});
|
|
256
|
-
}
|
|
257
|
-
__classPrivateFieldSet(this, _World_droppedAssetsMap, tempDroppedAssetsMap, "f");
|
|
258
|
-
resolve("Success!");
|
|
259
|
-
})
|
|
260
|
-
.catch((error) => {
|
|
261
|
-
reject(getErrorMessage(error));
|
|
262
|
-
// reject(new Error(getErrorMessage(error)));
|
|
263
|
-
});
|
|
264
|
-
});
|
|
265
|
-
}
|
|
266
|
-
/**
|
|
267
|
-
* @summary
|
|
268
|
-
* Update multiple custom text dropped assets with a single style while preserving text for specified dropped assets only.
|
|
269
|
-
*
|
|
270
|
-
* @usage
|
|
271
|
-
* ```ts
|
|
272
|
-
* const droppedAssetsToUpdate = [world.droppedAssets["6"], world.droppedAssets["12"]];
|
|
273
|
-
* const style = {
|
|
274
|
-
* "textColor": "#abc123",
|
|
275
|
-
* "textFontFamily": "Arial",
|
|
276
|
-
* "textSize": 40,
|
|
277
|
-
* "textWeight": "normal",
|
|
278
|
-
* "textWidth": 200
|
|
279
|
-
* };
|
|
280
|
-
* await world.moveVisitors(droppedAssetsToUpdate, style);
|
|
281
|
-
* ```
|
|
282
|
-
*
|
|
283
|
-
* @result
|
|
284
|
-
* Updates each DroppedAsset instance and world.droppedAssets map.
|
|
285
|
-
*/
|
|
286
|
-
updateCustomTextDroppedAssets(droppedAssetsToUpdate, style) {
|
|
287
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
288
|
-
const allPromises = [];
|
|
289
|
-
droppedAssetsToUpdate.forEach((a) => {
|
|
290
|
-
allPromises.push(a.updateCustomText(style, a.text));
|
|
291
|
-
});
|
|
292
|
-
const outcomes = yield Promise.allSettled(allPromises);
|
|
293
|
-
return outcomes;
|
|
294
|
-
});
|
|
295
|
-
}
|
|
296
|
-
/**
|
|
297
|
-
* @summary
|
|
298
|
-
* Replace the current scene of a world.
|
|
299
|
-
*
|
|
300
|
-
* @usage
|
|
301
|
-
* ```ts
|
|
302
|
-
* const droppedAssetsToUpdate = [world.droppedAssets["6"], world.droppedAssets["12"]]
|
|
303
|
-
* const style = {
|
|
304
|
-
* "textColor": "#abc123",
|
|
305
|
-
* "textFontFamily": "Arial",
|
|
306
|
-
* "textSize": 40,
|
|
307
|
-
* "textWeight": "normal",
|
|
308
|
-
* "textWidth": 200
|
|
309
|
-
* }
|
|
310
|
-
* await world.replaceScene(SCENE_ID);
|
|
311
|
-
* ```
|
|
312
|
-
*/
|
|
313
|
-
// scenes
|
|
314
|
-
replaceScene(sceneId) {
|
|
315
|
-
return new Promise((resolve, reject) => {
|
|
316
|
-
this.topia.axios
|
|
317
|
-
.put(`/world/${this.urlSlug}/change-scene`, { sceneId }, this.requestOptions)
|
|
318
|
-
.then(() => {
|
|
319
|
-
resolve("Success!");
|
|
320
|
-
})
|
|
321
|
-
.catch((error) => {
|
|
322
|
-
reject(new Error(getErrorMessage(error)));
|
|
323
|
-
});
|
|
324
|
-
});
|
|
325
|
-
}
|
|
326
|
-
}
|
|
327
|
-
_World_droppedAssetsMap = new WeakMap(), _World_visitorsMap = new WeakMap();
|
|
328
|
-
export default World;
|
|
@@ -1,37 +0,0 @@
|
|
|
1
|
-
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
2
|
-
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
3
|
-
return new (P || (P = Promise))(function (resolve, reject) {
|
|
4
|
-
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
5
|
-
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
6
|
-
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
7
|
-
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
8
|
-
});
|
|
9
|
-
};
|
|
10
|
-
import axios from "axios";
|
|
11
|
-
import MockAdapter from "axios-mock-adapter";
|
|
12
|
-
import { AssetFactory } from "factories";
|
|
13
|
-
import { Topia } from "controllers/Topia";
|
|
14
|
-
const apiDomain = "api.topia.io";
|
|
15
|
-
describe("Asset Class", () => {
|
|
16
|
-
let Asset, mock, testAsset, topia;
|
|
17
|
-
beforeEach(() => __awaiter(void 0, void 0, void 0, function* () {
|
|
18
|
-
mock = new MockAdapter(axios);
|
|
19
|
-
topia = new Topia({
|
|
20
|
-
apiDomain: "api.topia.io",
|
|
21
|
-
apiKey: "exampleKey",
|
|
22
|
-
interactiveKey: "key",
|
|
23
|
-
interactiveSecret: "secret",
|
|
24
|
-
});
|
|
25
|
-
Asset = new AssetFactory(topia);
|
|
26
|
-
testAsset = Asset.create("test");
|
|
27
|
-
}));
|
|
28
|
-
afterEach(() => {
|
|
29
|
-
mock.restore();
|
|
30
|
-
jest.resetAllMocks();
|
|
31
|
-
});
|
|
32
|
-
it("should return an array of assets owned by specific email address", () => __awaiter(void 0, void 0, void 0, function* () {
|
|
33
|
-
mock.onGet(`https://${apiDomain}/api/assets/topia-assets`).reply(200, "Success!");
|
|
34
|
-
yield testAsset.fetchPlatformAssets();
|
|
35
|
-
expect(mock.history.get.length).toBe(1);
|
|
36
|
-
}));
|
|
37
|
-
});
|
|
@@ -1,98 +0,0 @@
|
|
|
1
|
-
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
2
|
-
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
3
|
-
return new (P || (P = Promise))(function (resolve, reject) {
|
|
4
|
-
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
5
|
-
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
6
|
-
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
7
|
-
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
8
|
-
});
|
|
9
|
-
};
|
|
10
|
-
import { droppedAssets } from "__mocks__";
|
|
11
|
-
import { Topia } from "controllers";
|
|
12
|
-
import { DroppedAssetClickType, DroppedAssetMediaType } from "types/DroppedAssetTypes";
|
|
13
|
-
import axios from "axios";
|
|
14
|
-
import MockAdapter from "axios-mock-adapter";
|
|
15
|
-
import { DroppedAssetFactory } from "factories";
|
|
16
|
-
const apiDomain = "api.topia.io";
|
|
17
|
-
const args = droppedAssets[0];
|
|
18
|
-
const BASE_URL = `https://api.topia.io/api/world/magic/assets/${droppedAssets[0].id}`;
|
|
19
|
-
const id = droppedAssets[0].id;
|
|
20
|
-
describe("DroppedAsset Class", () => {
|
|
21
|
-
let DroppedAsset, mock, testDroppedAsset, topia;
|
|
22
|
-
beforeEach(() => __awaiter(void 0, void 0, void 0, function* () {
|
|
23
|
-
mock = new MockAdapter(axios);
|
|
24
|
-
topia = new Topia({
|
|
25
|
-
apiDomain,
|
|
26
|
-
apiKey: "key",
|
|
27
|
-
});
|
|
28
|
-
DroppedAsset = new DroppedAssetFactory(topia);
|
|
29
|
-
testDroppedAsset = yield DroppedAsset.create(id, "magic");
|
|
30
|
-
}));
|
|
31
|
-
afterEach(() => {
|
|
32
|
-
mock.restore();
|
|
33
|
-
jest.resetAllMocks();
|
|
34
|
-
});
|
|
35
|
-
it("should fetch dropped asset by id", () => __awaiter(void 0, void 0, void 0, function* () {
|
|
36
|
-
mock.onGet(BASE_URL).reply(200, droppedAssets[0]);
|
|
37
|
-
yield testDroppedAsset.fetchDroppedAssetById();
|
|
38
|
-
expect(mock.history.get.length).toBe(1);
|
|
39
|
-
expect(testDroppedAsset.urlSlug).toBeDefined();
|
|
40
|
-
}));
|
|
41
|
-
it("should update dropped asset broadcast zone", () => __awaiter(void 0, void 0, void 0, function* () {
|
|
42
|
-
mock.onPut(`${BASE_URL}/set-asset-broadcast`).reply(200, "Success!");
|
|
43
|
-
const broadcastArgs = Object.assign(Object.assign({}, args), { assetBroadcast: true, assetBroadcastAll: false, broadcasterEmail: "test@test.com" });
|
|
44
|
-
yield testDroppedAsset.updateBroadcast(broadcastArgs);
|
|
45
|
-
expect(mock.history.put.length).toBe(1);
|
|
46
|
-
}));
|
|
47
|
-
it("should update dropped asset click type", () => __awaiter(void 0, void 0, void 0, function* () {
|
|
48
|
-
mock.onPut(`${BASE_URL}/change-click-type`).reply(200, "Success!");
|
|
49
|
-
const clickTypeArgs = Object.assign(Object.assign({}, args), { clickType: DroppedAssetClickType.LINK, clickableLink: "www.test.com", clickableLinkTitle: "Test", portalName: "Test", position: {
|
|
50
|
-
x: 0,
|
|
51
|
-
y: 0,
|
|
52
|
-
} });
|
|
53
|
-
yield testDroppedAsset.updateClickType(clickTypeArgs);
|
|
54
|
-
expect(mock.history.put.length).toBe(1);
|
|
55
|
-
}));
|
|
56
|
-
it("should update dropped asset custom text", () => __awaiter(void 0, void 0, void 0, function* () {
|
|
57
|
-
mock.onPut(`${BASE_URL}/set-custom-text`).reply(200, "Success!");
|
|
58
|
-
yield testDroppedAsset.updateCustomText({ textColor: "#abc123" }, "hello world");
|
|
59
|
-
expect(mock.history.put.length).toBe(1);
|
|
60
|
-
}));
|
|
61
|
-
it("should update dropped asset media type", () => __awaiter(void 0, void 0, void 0, function* () {
|
|
62
|
-
mock.onPut(`${BASE_URL}/change-media-type`).reply(200, "Success!");
|
|
63
|
-
const mediaTypeArgs = Object.assign(Object.assign({}, args), { audioRadius: 0, audioVolume: -1, isVideo: true, mediaLink: "https://www.youtube.com/watch?v=dQw4w9WgXcQ", mediaName: "string", mediaType: DroppedAssetMediaType.LINK, portalName: "community", syncUserMedia: true });
|
|
64
|
-
yield testDroppedAsset.updateMediaType(mediaTypeArgs);
|
|
65
|
-
expect(mock.history.put.length).toBe(1);
|
|
66
|
-
}));
|
|
67
|
-
it("should update dropped asset mute zone", () => __awaiter(void 0, void 0, void 0, function* () {
|
|
68
|
-
mock.onPut(`${BASE_URL}/set-mute-zone`).reply(200, "Success!");
|
|
69
|
-
yield testDroppedAsset.updateMuteZone(true);
|
|
70
|
-
expect(mock.history.put.length).toBe(1);
|
|
71
|
-
}));
|
|
72
|
-
it("should update dropped asset position", () => __awaiter(void 0, void 0, void 0, function* () {
|
|
73
|
-
mock.onPut(`${BASE_URL}/set-position`).reply(200, "Success!");
|
|
74
|
-
yield testDroppedAsset.updatePosition(100, 100);
|
|
75
|
-
expect(mock.history.put.length).toBe(1);
|
|
76
|
-
}));
|
|
77
|
-
it("should update dropped asset private zone", () => __awaiter(void 0, void 0, void 0, function* () {
|
|
78
|
-
mock.onPut(`${BASE_URL}/set-private-zone`).reply(200, "Success!");
|
|
79
|
-
const privateZoneArgs = Object.assign(Object.assign({}, args), { isPrivateZone: true, isPrivateZoneChatDisabled: false, privateZoneUserCap: 10 });
|
|
80
|
-
yield testDroppedAsset.updatePrivateZone(privateZoneArgs);
|
|
81
|
-
expect(mock.history.put.length).toBe(1);
|
|
82
|
-
}));
|
|
83
|
-
it("should update dropped asset scale", () => __awaiter(void 0, void 0, void 0, function* () {
|
|
84
|
-
mock.onPut(`${BASE_URL}/change-scale`).reply(200, "Success!");
|
|
85
|
-
yield testDroppedAsset.updateScale(75);
|
|
86
|
-
expect(mock.history.put.length).toBe(1);
|
|
87
|
-
}));
|
|
88
|
-
it("should update dropped asset uploaded media selected", () => __awaiter(void 0, void 0, void 0, function* () {
|
|
89
|
-
mock.onPut(`${BASE_URL}/change-uploaded-media-selected`).reply(200, "Success!");
|
|
90
|
-
yield testDroppedAsset.updateUploadedMediaSelected("abc123");
|
|
91
|
-
expect(mock.history.put.length).toBe(1);
|
|
92
|
-
}));
|
|
93
|
-
it("should update dropped asset web image layers", () => __awaiter(void 0, void 0, void 0, function* () {
|
|
94
|
-
mock.onPut(`${BASE_URL}/set-webimage-layers`).reply(200, "Success!");
|
|
95
|
-
yield testDroppedAsset.updateWebImageLayers("test", "test");
|
|
96
|
-
expect(mock.history.put.length).toBe(1);
|
|
97
|
-
}));
|
|
98
|
-
});
|
|
@@ -1,50 +0,0 @@
|
|
|
1
|
-
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
2
|
-
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
3
|
-
return new (P || (P = Promise))(function (resolve, reject) {
|
|
4
|
-
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
5
|
-
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
6
|
-
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
7
|
-
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
8
|
-
});
|
|
9
|
-
};
|
|
10
|
-
import axios from "axios";
|
|
11
|
-
import MockAdapter from "axios-mock-adapter";
|
|
12
|
-
import { droppedAssets, scenes, worlds } from "__mocks__";
|
|
13
|
-
import { Topia } from "controllers";
|
|
14
|
-
import { UserFactory } from "factories";
|
|
15
|
-
const apiDomain = "api.topia.io";
|
|
16
|
-
const email = "test@email.com";
|
|
17
|
-
describe("User Class", () => {
|
|
18
|
-
let mock, testUser, topia, User;
|
|
19
|
-
beforeEach(() => {
|
|
20
|
-
mock = new MockAdapter(axios);
|
|
21
|
-
topia = new Topia({
|
|
22
|
-
apiDomain,
|
|
23
|
-
apiKey: "key",
|
|
24
|
-
});
|
|
25
|
-
User = new UserFactory(topia);
|
|
26
|
-
testUser = User.create(email);
|
|
27
|
-
});
|
|
28
|
-
afterEach(() => {
|
|
29
|
-
mock.restore();
|
|
30
|
-
jest.resetAllMocks();
|
|
31
|
-
});
|
|
32
|
-
it("should update user.worlds", () => __awaiter(void 0, void 0, void 0, function* () {
|
|
33
|
-
mock.onGet(`https://${apiDomain}/api/user/worlds`).reply(200, worlds);
|
|
34
|
-
yield testUser.fetchWorldsByKey();
|
|
35
|
-
expect(mock.history.get.length).toBe(1);
|
|
36
|
-
expect(Object.keys(testUser.worlds).length).toBe(Object.keys(worlds).length);
|
|
37
|
-
}));
|
|
38
|
-
it("should return an array of scenes owned by specific email address", () => __awaiter(void 0, void 0, void 0, function* () {
|
|
39
|
-
testUser.fetchScenesByEmail = jest.fn().mockReturnValue(scenes);
|
|
40
|
-
const mockScenes = yield testUser.fetchScenesByEmail();
|
|
41
|
-
expect(testUser.fetchScenesByEmail).toHaveBeenCalled();
|
|
42
|
-
expect(mockScenes).toBeDefined();
|
|
43
|
-
}));
|
|
44
|
-
it("should return an array of assets owned by specific email address", () => __awaiter(void 0, void 0, void 0, function* () {
|
|
45
|
-
testUser.fetchAssetsByEmail = jest.fn().mockReturnValue(droppedAssets);
|
|
46
|
-
const mockAssets = yield testUser.fetchAssetsByEmail("lina@topia.io");
|
|
47
|
-
expect(testUser.fetchAssetsByEmail).toHaveBeenCalled();
|
|
48
|
-
expect(mockAssets).toBeDefined();
|
|
49
|
-
}));
|
|
50
|
-
});
|
|
@@ -1,41 +0,0 @@
|
|
|
1
|
-
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
2
|
-
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
3
|
-
return new (P || (P = Promise))(function (resolve, reject) {
|
|
4
|
-
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
5
|
-
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
6
|
-
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
7
|
-
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
8
|
-
});
|
|
9
|
-
};
|
|
10
|
-
import axios from "axios";
|
|
11
|
-
import MockAdapter from "axios-mock-adapter";
|
|
12
|
-
import { visitors } from "../../__mocks__";
|
|
13
|
-
import { Topia } from "controllers";
|
|
14
|
-
import { VisitorFactory } from "factories";
|
|
15
|
-
const apiDomain = "api.topia.io";
|
|
16
|
-
const id = visitors["1"].playerId;
|
|
17
|
-
describe("Visitor Class", () => {
|
|
18
|
-
let mock, testVisitor, topia, Visitor;
|
|
19
|
-
beforeEach(() => {
|
|
20
|
-
mock = new MockAdapter(axios);
|
|
21
|
-
topia = new Topia({
|
|
22
|
-
apiDomain,
|
|
23
|
-
apiKey: "key",
|
|
24
|
-
});
|
|
25
|
-
Visitor = new VisitorFactory(topia);
|
|
26
|
-
testVisitor = Visitor.create(id, "magic");
|
|
27
|
-
});
|
|
28
|
-
afterEach(() => {
|
|
29
|
-
mock.restore();
|
|
30
|
-
jest.resetAllMocks();
|
|
31
|
-
});
|
|
32
|
-
it("should move a list of visitors to uniquely specified coordinates", () => __awaiter(void 0, void 0, void 0, function* () {
|
|
33
|
-
mock.onPut(`https://${apiDomain}/api/world/magic/visitors/${id}/move`).reply(200, "Success!");
|
|
34
|
-
yield testVisitor.moveVisitor({
|
|
35
|
-
shouldTeleportVisitor: true,
|
|
36
|
-
x: 100,
|
|
37
|
-
y: 100,
|
|
38
|
-
});
|
|
39
|
-
expect(mock.history.put.length).toBe(1);
|
|
40
|
-
}));
|
|
41
|
-
});
|
|
@@ -1,77 +0,0 @@
|
|
|
1
|
-
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
2
|
-
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
3
|
-
return new (P || (P = Promise))(function (resolve, reject) {
|
|
4
|
-
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
5
|
-
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
6
|
-
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
7
|
-
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
8
|
-
});
|
|
9
|
-
};
|
|
10
|
-
import axios from "axios";
|
|
11
|
-
import MockAdapter from "axios-mock-adapter";
|
|
12
|
-
import { visitors, worlds } from "../../__mocks__";
|
|
13
|
-
import { Visitor, Topia } from "controllers";
|
|
14
|
-
import { WorldFactory } from "factories";
|
|
15
|
-
// const args = worlds[1];
|
|
16
|
-
const BASE_URL = "https://api.topia.io/api/world/magic";
|
|
17
|
-
const urlSlug = worlds[1].urlSlug;
|
|
18
|
-
describe("World Class", () => {
|
|
19
|
-
let mock, testWorld, topia, World;
|
|
20
|
-
beforeEach(() => {
|
|
21
|
-
mock = new MockAdapter(axios);
|
|
22
|
-
topia = new Topia({
|
|
23
|
-
apiDomain: "api.topia.io",
|
|
24
|
-
apiKey: "key",
|
|
25
|
-
});
|
|
26
|
-
World = new WorldFactory(topia);
|
|
27
|
-
testWorld = World.create(urlSlug);
|
|
28
|
-
});
|
|
29
|
-
afterEach(() => {
|
|
30
|
-
mock.restore();
|
|
31
|
-
jest.resetAllMocks();
|
|
32
|
-
});
|
|
33
|
-
it("should return details of a world", () => __awaiter(void 0, void 0, void 0, function* () {
|
|
34
|
-
expect(testWorld.urlSlug).toEqual("magic");
|
|
35
|
-
testWorld.fetchDetails = jest.fn().mockReturnValue(worlds[1]);
|
|
36
|
-
const mockDetails = yield testWorld.fetchDetails();
|
|
37
|
-
expect(testWorld.fetchDetails).toHaveBeenCalled();
|
|
38
|
-
expect(mockDetails).toBeDefined();
|
|
39
|
-
}));
|
|
40
|
-
// it("should update details of a world", async () => {
|
|
41
|
-
// mock.onPut(`${BASE_URL}/world-details`).reply(200, "Success!");
|
|
42
|
-
// const worldArgs = {
|
|
43
|
-
// ...args,
|
|
44
|
-
// controls: {
|
|
45
|
-
// allowMuteAll: false,
|
|
46
|
-
// },
|
|
47
|
-
// description: "testing update details",
|
|
48
|
-
// name: "magic",
|
|
49
|
-
// };
|
|
50
|
-
// await testWorld.updateDetails(worldArgs);
|
|
51
|
-
// expect(mock.history.put.length).toBe(1);
|
|
52
|
-
// expect(testWorld.urlSlug).toEqual("magic");
|
|
53
|
-
// });
|
|
54
|
-
it("should move all visitors within a world to a single set of coordinates", () => __awaiter(void 0, void 0, void 0, function* () {
|
|
55
|
-
mock.onGet(`${BASE_URL}/visitors`).reply(200, visitors);
|
|
56
|
-
mock.onPut(`${BASE_URL}/visitors/1/move`).reply(200, "Success!");
|
|
57
|
-
const args = { shouldFetchVisitors: true, shouldTeleportVisitors: true, scatterVisitorsBy: 100, x: 20, y: 40 };
|
|
58
|
-
yield testWorld.moveAllVisitors(args);
|
|
59
|
-
expect(mock.history.put.length).toBe(Object.keys(visitors).length);
|
|
60
|
-
}));
|
|
61
|
-
it("should return success if world doesn't have visitors", () => __awaiter(void 0, void 0, void 0, function* () {
|
|
62
|
-
const args = { shouldFetchVisitors: false, scatterVisitorsBy: 100, x: 20, y: 40 };
|
|
63
|
-
yield testWorld.moveAllVisitors(args);
|
|
64
|
-
expect(mock.history.put.length).toBe(0);
|
|
65
|
-
}));
|
|
66
|
-
it("should move a list of visitors to uniquely specified coordinates", () => __awaiter(void 0, void 0, void 0, function* () {
|
|
67
|
-
mock.onPut(`${BASE_URL}/visitors/1/move`).reply(200, "Success!");
|
|
68
|
-
const v1 = new Visitor(topia, visitors["1"].playerId, urlSlug, { args: visitors["1"] });
|
|
69
|
-
const v2 = new Visitor(topia, visitors["2"].playerId, urlSlug, { args: visitors["2"] });
|
|
70
|
-
const testVisitors = [
|
|
71
|
-
{ visitorObj: v1, shouldTeleportVisitor: true, x: 0, y: 0 },
|
|
72
|
-
{ visitorObj: v2, shouldTeleportVisitor: false, x: 100, y: 100 },
|
|
73
|
-
];
|
|
74
|
-
yield testWorld.moveVisitors(testVisitors);
|
|
75
|
-
expect(mock.history.put.length).toBe(2);
|
|
76
|
-
}));
|
|
77
|
-
});
|
|
@@ -1,7 +0,0 @@
|
|
|
1
|
-
export { Asset } from "./Asset";
|
|
2
|
-
export { DroppedAsset } from "./DroppedAsset";
|
|
3
|
-
export { SDKController } from "./SDKController";
|
|
4
|
-
export { User } from "./User";
|
|
5
|
-
export { Visitor } from "./Visitor";
|
|
6
|
-
export { World } from "./World";
|
|
7
|
-
export { Topia } from "./Topia";
|