@rtsdk/topia 0.0.8 → 0.0.10
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/__mocks__/assets.js +241 -0
- package/dist/__mocks__/index.js +2 -0
- package/dist/__mocks__/scenes.js +104 -0
- package/dist/__mocks__/visitors.js +43 -16
- package/dist/__mocks__/worlds.js +10 -9
- package/dist/controllers/Asset.js +20 -0
- package/dist/controllers/DroppedAsset.js +151 -0
- package/dist/controllers/User.js +63 -0
- package/dist/controllers/Visitor.js +31 -0
- package/dist/controllers/World.js +165 -101
- package/dist/controllers/__tests__/asset.test.js +23 -0
- package/dist/controllers/__tests__/droppedAsset.test.js +93 -0
- package/dist/controllers/__tests__/user.test.js +23 -0
- package/dist/controllers/__tests__/visitor.test.js +24 -0
- package/dist/controllers/__tests__/world.test.js +62 -98
- package/dist/controllers/index.js +4 -0
- package/dist/index.js +464 -126
- package/dist/{types/Visitor.js → interfaces/AssetInterfaces.js} +0 -0
- package/dist/interfaces/DroppedAssetInterfaces.js +1 -0
- package/dist/interfaces/VisitorInterfaces.js +1 -0
- package/dist/interfaces/WorldInterfaces.js +1 -0
- package/dist/interfaces/index.js +4 -0
- package/dist/types/DroppedAssetTypes.js +12 -0
- package/dist/types/VisitorTypes.js +1 -0
- package/dist/types/index.js +2 -1
- package/dist/utils/__tests__/removeUndefined.test.js +10 -0
- package/dist/utils/__tests__/scatterVisitors.test.js +11 -0
- package/dist/utils/createDroppedAsset.js +72 -0
- package/dist/utils/getErrorMessage.js +5 -0
- package/dist/utils/index.js +4 -0
- package/dist/utils/publicAPI.js +10 -0
- package/dist/utils/removeUndefined.js +8 -0
- package/dist/utils/scatterVisitors.js +5 -0
- package/package.json +3 -1
|
@@ -0,0 +1,63 @@
|
|
|
1
|
+
var __classPrivateFieldSet = (this && this.__classPrivateFieldSet) || function (receiver, state, value, kind, f) {
|
|
2
|
+
if (kind === "m") throw new TypeError("Private method is not writable");
|
|
3
|
+
if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a setter");
|
|
4
|
+
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");
|
|
5
|
+
return (kind === "a" ? f.call(receiver, value) : f ? f.value = value : state.set(receiver, value)), value;
|
|
6
|
+
};
|
|
7
|
+
var __classPrivateFieldGet = (this && this.__classPrivateFieldGet) || function (receiver, state, kind, f) {
|
|
8
|
+
if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a getter");
|
|
9
|
+
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");
|
|
10
|
+
return kind === "m" ? f : kind === "a" ? f.call(receiver) : f ? f.value : state.get(receiver);
|
|
11
|
+
};
|
|
12
|
+
var _User_worldsMap;
|
|
13
|
+
import { World } from "controllers/World";
|
|
14
|
+
import { getErrorMessage, publicAPI } from "utils";
|
|
15
|
+
export class User {
|
|
16
|
+
constructor({ apiKey, email }) {
|
|
17
|
+
_User_worldsMap.set(this, void 0);
|
|
18
|
+
__classPrivateFieldSet(this, _User_worldsMap, {}, "f");
|
|
19
|
+
this.apiKey = apiKey;
|
|
20
|
+
this.email = email;
|
|
21
|
+
}
|
|
22
|
+
get worlds() {
|
|
23
|
+
return __classPrivateFieldGet(this, _User_worldsMap, "f");
|
|
24
|
+
}
|
|
25
|
+
fetchScenesByEmail() {
|
|
26
|
+
return new Promise((resolve, reject) => {
|
|
27
|
+
if (!this.email)
|
|
28
|
+
reject("There is no email associated with this user.");
|
|
29
|
+
publicAPI(this.apiKey)
|
|
30
|
+
.get(`/scenes/my-scenes?email=${this.email}`)
|
|
31
|
+
.then((response) => {
|
|
32
|
+
resolve(response.data);
|
|
33
|
+
})
|
|
34
|
+
.catch((error) => {
|
|
35
|
+
reject(new Error(getErrorMessage(error)));
|
|
36
|
+
});
|
|
37
|
+
});
|
|
38
|
+
}
|
|
39
|
+
fetchWorldsByKey() {
|
|
40
|
+
return new Promise((resolve, reject) => {
|
|
41
|
+
publicAPI(this.apiKey)
|
|
42
|
+
.get("/user/worlds")
|
|
43
|
+
.then((response) => {
|
|
44
|
+
const tempWorldsMap = {};
|
|
45
|
+
for (const i in response.data) {
|
|
46
|
+
const worldDetails = response.data[i];
|
|
47
|
+
tempWorldsMap[worldDetails.urlSlug] = new World({
|
|
48
|
+
apiKey: this.apiKey,
|
|
49
|
+
args: worldDetails,
|
|
50
|
+
urlSlug: worldDetails.urlSlug,
|
|
51
|
+
});
|
|
52
|
+
}
|
|
53
|
+
__classPrivateFieldSet(this, _User_worldsMap, tempWorldsMap, "f");
|
|
54
|
+
resolve("Success!");
|
|
55
|
+
})
|
|
56
|
+
.catch((error) => {
|
|
57
|
+
reject(new Error(getErrorMessage(error)));
|
|
58
|
+
});
|
|
59
|
+
});
|
|
60
|
+
}
|
|
61
|
+
}
|
|
62
|
+
_User_worldsMap = new WeakMap();
|
|
63
|
+
export default User;
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
import { getErrorMessage, publicAPI } from "utils";
|
|
2
|
+
export class Visitor {
|
|
3
|
+
constructor({ apiKey, args, urlSlug }) {
|
|
4
|
+
Object.assign(this, args);
|
|
5
|
+
this.apiKey = apiKey;
|
|
6
|
+
this.moveTo = args.moveTo;
|
|
7
|
+
this.playerId = args.playerId;
|
|
8
|
+
this.urlSlug = urlSlug;
|
|
9
|
+
this.moveVisitor;
|
|
10
|
+
}
|
|
11
|
+
moveVisitor(shouldTeleportVisitor, x, y) {
|
|
12
|
+
return new Promise((resolve, reject) => {
|
|
13
|
+
publicAPI(this.apiKey)
|
|
14
|
+
.put(`/world/${this.urlSlug}/visitors/${this.playerId}/move`, {
|
|
15
|
+
moveTo: {
|
|
16
|
+
x,
|
|
17
|
+
y,
|
|
18
|
+
},
|
|
19
|
+
teleport: shouldTeleportVisitor,
|
|
20
|
+
})
|
|
21
|
+
.then(() => {
|
|
22
|
+
this.moveTo = { x, y };
|
|
23
|
+
resolve("Success!");
|
|
24
|
+
})
|
|
25
|
+
.catch((error) => {
|
|
26
|
+
reject(new Error(getErrorMessage(error)));
|
|
27
|
+
});
|
|
28
|
+
});
|
|
29
|
+
}
|
|
30
|
+
}
|
|
31
|
+
export default Visitor;
|
|
@@ -7,116 +7,180 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
|
|
|
7
7
|
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
8
8
|
});
|
|
9
9
|
};
|
|
10
|
-
var
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
if (f) throw new TypeError("Generator is already executing.");
|
|
16
|
-
while (g && (g = 0, op[0] && (_ = 0)), _) try {
|
|
17
|
-
if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
|
|
18
|
-
if (y = 0, t) op = [op[0] & 2, t.value];
|
|
19
|
-
switch (op[0]) {
|
|
20
|
-
case 0: case 1: t = op; break;
|
|
21
|
-
case 4: _.label++; return { value: op[1], done: false };
|
|
22
|
-
case 5: _.label++; y = op[1]; op = [0]; continue;
|
|
23
|
-
case 7: op = _.ops.pop(); _.trys.pop(); continue;
|
|
24
|
-
default:
|
|
25
|
-
if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
|
|
26
|
-
if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
|
|
27
|
-
if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
|
|
28
|
-
if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
|
|
29
|
-
if (t[2]) _.ops.pop();
|
|
30
|
-
_.trys.pop(); continue;
|
|
31
|
-
}
|
|
32
|
-
op = body.call(thisArg, _);
|
|
33
|
-
} catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
|
|
34
|
-
if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
|
|
35
|
-
}
|
|
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;
|
|
36
15
|
};
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
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
|
+
import { getErrorMessage, publicAPI, removeUndefined, scatterVisitors } from "utils";
|
|
23
|
+
import { DroppedAsset } from "controllers/DroppedAsset";
|
|
24
|
+
import { Visitor } from "controllers/Visitor";
|
|
25
|
+
export class World {
|
|
26
|
+
constructor({ apiKey, args, urlSlug }) {
|
|
27
|
+
_World_droppedAssetsMap.set(this, void 0);
|
|
28
|
+
_World_visitorsMap.set(this, void 0);
|
|
29
|
+
Object.assign(this, args);
|
|
30
|
+
__classPrivateFieldSet(this, _World_droppedAssetsMap, {}, "f");
|
|
31
|
+
__classPrivateFieldSet(this, _World_visitorsMap, {}, "f");
|
|
41
32
|
this.apiKey = apiKey;
|
|
42
33
|
this.urlSlug = urlSlug;
|
|
43
34
|
}
|
|
44
|
-
|
|
45
|
-
return
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
35
|
+
get droppedAssets() {
|
|
36
|
+
return __classPrivateFieldGet(this, _World_droppedAssetsMap, "f");
|
|
37
|
+
}
|
|
38
|
+
get visitors() {
|
|
39
|
+
return __classPrivateFieldGet(this, _World_visitorsMap, "f");
|
|
40
|
+
}
|
|
41
|
+
// world details
|
|
42
|
+
fetchDetails() {
|
|
43
|
+
return new Promise((resolve, reject) => {
|
|
44
|
+
publicAPI(this.apiKey)
|
|
45
|
+
.get(`/world/${this.urlSlug}/world-details`)
|
|
46
|
+
.then((response) => {
|
|
47
|
+
Object.assign(this, response.data);
|
|
48
|
+
resolve("Success!");
|
|
49
|
+
})
|
|
50
|
+
.catch((error) => {
|
|
51
|
+
reject(new Error(getErrorMessage(error)));
|
|
57
52
|
});
|
|
58
53
|
});
|
|
59
|
-
}
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
54
|
+
}
|
|
55
|
+
updateDetails({ controls, description, forceAuthOnLogin, height, name, spawnPosition, width, }) {
|
|
56
|
+
const payload = {
|
|
57
|
+
controls,
|
|
58
|
+
description,
|
|
59
|
+
forceAuthOnLogin,
|
|
60
|
+
height,
|
|
61
|
+
name,
|
|
62
|
+
spawnPosition,
|
|
63
|
+
width,
|
|
64
|
+
};
|
|
65
|
+
return new Promise((resolve, reject) => {
|
|
66
|
+
publicAPI(this.apiKey)
|
|
67
|
+
.put(`/world/${this.urlSlug}/world-details`, payload)
|
|
68
|
+
.then(() => {
|
|
69
|
+
const cleanPayload = removeUndefined(payload);
|
|
70
|
+
Object.assign(this, cleanPayload);
|
|
71
|
+
resolve("Success!");
|
|
72
|
+
})
|
|
73
|
+
.catch((error) => {
|
|
74
|
+
reject(new Error(getErrorMessage(error)));
|
|
73
75
|
});
|
|
74
76
|
});
|
|
75
|
-
}
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
headers: { Authorization: _this.apiKey },
|
|
91
|
-
body: {
|
|
92
|
-
moveTo: {
|
|
93
|
-
x: visitor.coordinates.x,
|
|
94
|
-
y: visitor.coordinates.y
|
|
95
|
-
},
|
|
96
|
-
teleport: true
|
|
97
|
-
}
|
|
98
|
-
};
|
|
99
|
-
axios
|
|
100
|
-
.put("".concat(API_URL, "/world/").concat(_this.urlSlug, "/visitors/").concat(visitor.id, "/move"), requestOptions)
|
|
101
|
-
.then(function (response) {
|
|
102
|
-
resolve(response.data);
|
|
103
|
-
})["catch"](reject);
|
|
104
|
-
});
|
|
105
|
-
allPromises.push(promise);
|
|
106
|
-
return [2 /*return*/];
|
|
107
|
-
});
|
|
108
|
-
}); });
|
|
109
|
-
return [4 /*yield*/, Promise.allSettled(allPromises)];
|
|
110
|
-
case 1:
|
|
111
|
-
outcomes = _a.sent();
|
|
112
|
-
// const succeeded = outcomes.filter((o) => o.status === "fulfilled");
|
|
113
|
-
// const failed = outcomes.filter((o) => o.status === "rejected");
|
|
114
|
-
return [2 /*return*/, outcomes];
|
|
77
|
+
}
|
|
78
|
+
// visitors
|
|
79
|
+
fetchVisitors() {
|
|
80
|
+
return new Promise((resolve, reject) => {
|
|
81
|
+
publicAPI(this.apiKey)
|
|
82
|
+
.get(`/world/${this.urlSlug}/visitors`)
|
|
83
|
+
.then((response) => {
|
|
84
|
+
// create temp map and then update private property only once
|
|
85
|
+
const tempVisitorsMap = {};
|
|
86
|
+
for (const playerId in response.data) {
|
|
87
|
+
tempVisitorsMap[playerId] = new Visitor({
|
|
88
|
+
apiKey: this.apiKey,
|
|
89
|
+
args: response.data[playerId],
|
|
90
|
+
urlSlug: this.urlSlug,
|
|
91
|
+
});
|
|
115
92
|
}
|
|
93
|
+
__classPrivateFieldSet(this, _World_visitorsMap, tempVisitorsMap, "f");
|
|
94
|
+
resolve("Success!");
|
|
95
|
+
})
|
|
96
|
+
.catch((error) => {
|
|
97
|
+
reject(new Error(getErrorMessage(error)));
|
|
116
98
|
});
|
|
117
99
|
});
|
|
118
|
-
}
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
100
|
+
}
|
|
101
|
+
currentVisitors() {
|
|
102
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
103
|
+
try {
|
|
104
|
+
yield this.fetchVisitors();
|
|
105
|
+
return this.visitors;
|
|
106
|
+
}
|
|
107
|
+
catch (error) {
|
|
108
|
+
return error;
|
|
109
|
+
}
|
|
110
|
+
});
|
|
111
|
+
}
|
|
112
|
+
moveAllVisitors({ shouldFetchVisitors = true, shouldTeleportVisitors = true, scatterVisitorsBy = 0, x, y, }) {
|
|
113
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
114
|
+
if (shouldFetchVisitors)
|
|
115
|
+
yield this.fetchVisitors();
|
|
116
|
+
const allPromises = [];
|
|
117
|
+
if (!this.visitors)
|
|
118
|
+
return;
|
|
119
|
+
const objectKeys = Object.keys(this.visitors);
|
|
120
|
+
objectKeys.forEach((key) => allPromises.push(__classPrivateFieldGet(this, _World_visitorsMap, "f")[key].moveVisitor(shouldTeleportVisitors, scatterVisitors(x, scatterVisitorsBy), scatterVisitors(y, scatterVisitorsBy))));
|
|
121
|
+
const outcomes = yield Promise.allSettled(allPromises);
|
|
122
|
+
return outcomes;
|
|
123
|
+
});
|
|
124
|
+
}
|
|
125
|
+
moveVisitors(visitorsToMove) {
|
|
126
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
127
|
+
const allPromises = [];
|
|
128
|
+
visitorsToMove.forEach((v) => {
|
|
129
|
+
allPromises.push(v.visitorObj.moveVisitor(v.shouldTeleportVisitor, v.x, v.y));
|
|
130
|
+
});
|
|
131
|
+
const outcomes = yield Promise.allSettled(allPromises);
|
|
132
|
+
return outcomes;
|
|
133
|
+
});
|
|
134
|
+
}
|
|
135
|
+
// dropped assets
|
|
136
|
+
fetchDroppedAssets() {
|
|
137
|
+
return new Promise((resolve, reject) => {
|
|
138
|
+
publicAPI(this.apiKey)
|
|
139
|
+
.get(`/world/${this.urlSlug}/assets`)
|
|
140
|
+
.then((response) => {
|
|
141
|
+
// create temp map and then update private property only once
|
|
142
|
+
const tempDroppedAssetsMap = {};
|
|
143
|
+
for (const id in response.data) {
|
|
144
|
+
// tempDroppedAssetsMap[id] = createDroppedAsset(this.apiKey, response.data[id], this.urlSlug);
|
|
145
|
+
tempDroppedAssetsMap[id] = new DroppedAsset({
|
|
146
|
+
apiKey: this.apiKey,
|
|
147
|
+
id,
|
|
148
|
+
args: response.data[id],
|
|
149
|
+
urlSlug: this.urlSlug,
|
|
150
|
+
});
|
|
151
|
+
}
|
|
152
|
+
__classPrivateFieldSet(this, _World_droppedAssetsMap, tempDroppedAssetsMap, "f");
|
|
153
|
+
resolve("Success!");
|
|
154
|
+
})
|
|
155
|
+
.catch((error) => {
|
|
156
|
+
reject(new Error(getErrorMessage(error)));
|
|
157
|
+
});
|
|
158
|
+
});
|
|
159
|
+
}
|
|
160
|
+
updateCustomTextDroppedAssets(droppedAssetsToUpdate, style) {
|
|
161
|
+
return __awaiter(this, void 0, void 0, function* () {
|
|
162
|
+
// adds ability to update any styles for specified dropped assets only while preserving text
|
|
163
|
+
const allPromises = [];
|
|
164
|
+
droppedAssetsToUpdate.forEach((a) => {
|
|
165
|
+
allPromises.push(a.updateCustomText(style, a.text));
|
|
166
|
+
});
|
|
167
|
+
const outcomes = yield Promise.allSettled(allPromises);
|
|
168
|
+
return outcomes;
|
|
169
|
+
});
|
|
170
|
+
}
|
|
171
|
+
// scenes
|
|
172
|
+
replaceScene(sceneId) {
|
|
173
|
+
return new Promise((resolve, reject) => {
|
|
174
|
+
publicAPI(this.apiKey)
|
|
175
|
+
.put(`/world/${this.urlSlug}/change-scene`, { sceneId })
|
|
176
|
+
.then(() => {
|
|
177
|
+
resolve("Success!");
|
|
178
|
+
})
|
|
179
|
+
.catch((error) => {
|
|
180
|
+
reject(new Error(getErrorMessage(error)));
|
|
181
|
+
});
|
|
182
|
+
});
|
|
183
|
+
}
|
|
184
|
+
}
|
|
185
|
+
_World_droppedAssetsMap = new WeakMap(), _World_visitorsMap = new WeakMap();
|
|
122
186
|
export default World;
|
|
@@ -0,0 +1,23 @@
|
|
|
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 { assets } from "../../__mocks__";
|
|
11
|
+
import { Asset } from "..";
|
|
12
|
+
afterEach(() => {
|
|
13
|
+
jest.resetAllMocks();
|
|
14
|
+
});
|
|
15
|
+
describe("Asset Class", () => {
|
|
16
|
+
it("should return an array of assets owned by specific email address", () => __awaiter(void 0, void 0, void 0, function* () {
|
|
17
|
+
const testAsset = new Asset({ apiKey: "key", args: { id: "abc123" } });
|
|
18
|
+
testAsset.fetchAssetsByEmail = jest.fn().mockReturnValue(assets);
|
|
19
|
+
const mockAssets = yield testAsset.fetchAssetsByEmail("lina@topia.io");
|
|
20
|
+
expect(testAsset.fetchAssetsByEmail).toHaveBeenCalled();
|
|
21
|
+
expect(mockAssets).toBeDefined();
|
|
22
|
+
}));
|
|
23
|
+
});
|
|
@@ -0,0 +1,93 @@
|
|
|
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 { DroppedAsset } from "..";
|
|
12
|
+
import { DroppedAssetClickType, DroppedAssetMediaType } from "../../types/DroppedAssetTypes";
|
|
13
|
+
import axios from "axios";
|
|
14
|
+
import MockAdapter from "axios-mock-adapter";
|
|
15
|
+
const BASE_URL = `https://api.topia.io/api/world/magic/assets/${droppedAssets[0].id}`;
|
|
16
|
+
const apiKey = "key";
|
|
17
|
+
const args = droppedAssets[0];
|
|
18
|
+
const id = droppedAssets[0].id;
|
|
19
|
+
const urlSlug = "magic";
|
|
20
|
+
describe("DroppedAsset Class", () => {
|
|
21
|
+
let mock, testDroppedAsset;
|
|
22
|
+
beforeEach(() => {
|
|
23
|
+
mock = new MockAdapter(axios);
|
|
24
|
+
testDroppedAsset = new DroppedAsset({ apiKey, id, args, urlSlug });
|
|
25
|
+
});
|
|
26
|
+
afterEach(() => {
|
|
27
|
+
mock.restore();
|
|
28
|
+
jest.resetAllMocks();
|
|
29
|
+
});
|
|
30
|
+
it("should fetch dropped asset by id", () => __awaiter(void 0, void 0, void 0, function* () {
|
|
31
|
+
testDroppedAsset.fetchDroppedAssetById = jest.fn().mockReturnValue(droppedAssets[0]);
|
|
32
|
+
const mockDroppedAssets = yield testDroppedAsset.fetchDroppedAssetById();
|
|
33
|
+
expect(testDroppedAsset.fetchDroppedAssetById).toHaveBeenCalled();
|
|
34
|
+
expect(mockDroppedAssets).toBeDefined();
|
|
35
|
+
}));
|
|
36
|
+
it("should update dropped asset broadcast zone", () => __awaiter(void 0, void 0, void 0, function* () {
|
|
37
|
+
mock.onPut(`${BASE_URL}/set-asset-broadcast`).reply(200, "Success!");
|
|
38
|
+
const broadcastArgs = Object.assign(Object.assign({}, args), { assetBroadcast: true, assetBroadcastAll: false, broadcasterEmail: "test@test.com" });
|
|
39
|
+
yield testDroppedAsset.updateBroadcast(broadcastArgs);
|
|
40
|
+
expect(mock.history.put.length).toBe(1);
|
|
41
|
+
}));
|
|
42
|
+
it("should update dropped asset click type", () => __awaiter(void 0, void 0, void 0, function* () {
|
|
43
|
+
mock.onPut(`${BASE_URL}/change-click-type`).reply(200, "Success!");
|
|
44
|
+
const clickTypeArgs = Object.assign(Object.assign({}, args), { clickType: DroppedAssetClickType.LINK, clickableLink: "www.test.com", clickableLinkTitle: "Test", portalName: "Test", position: {
|
|
45
|
+
x: 0,
|
|
46
|
+
y: 0,
|
|
47
|
+
} });
|
|
48
|
+
yield testDroppedAsset.updateClickType(clickTypeArgs);
|
|
49
|
+
expect(mock.history.put.length).toBe(1);
|
|
50
|
+
}));
|
|
51
|
+
it("should update dropped asset custom text", () => __awaiter(void 0, void 0, void 0, function* () {
|
|
52
|
+
mock.onPut(`${BASE_URL}/set-custom-text`).reply(200, "Success!");
|
|
53
|
+
yield testDroppedAsset.updateCustomText({ textColor: "#abc123" }, "hello world");
|
|
54
|
+
expect(mock.history.put.length).toBe(1);
|
|
55
|
+
}));
|
|
56
|
+
it("should update dropped asset media type", () => __awaiter(void 0, void 0, void 0, function* () {
|
|
57
|
+
mock.onPut(`${BASE_URL}/change-media-type`).reply(200, "Success!");
|
|
58
|
+
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 });
|
|
59
|
+
yield testDroppedAsset.updateMediaType(mediaTypeArgs);
|
|
60
|
+
expect(mock.history.put.length).toBe(1);
|
|
61
|
+
}));
|
|
62
|
+
it("should update dropped asset mute zone", () => __awaiter(void 0, void 0, void 0, function* () {
|
|
63
|
+
mock.onPut(`${BASE_URL}/set-mute-zone`).reply(200, "Success!");
|
|
64
|
+
yield testDroppedAsset.updateMuteZone(true);
|
|
65
|
+
expect(mock.history.put.length).toBe(1);
|
|
66
|
+
}));
|
|
67
|
+
it("should update dropped asset position", () => __awaiter(void 0, void 0, void 0, function* () {
|
|
68
|
+
mock.onPut(`${BASE_URL}/set-position`).reply(200, "Success!");
|
|
69
|
+
yield testDroppedAsset.updatePosition(100, 100);
|
|
70
|
+
expect(mock.history.put.length).toBe(1);
|
|
71
|
+
}));
|
|
72
|
+
it("should update dropped asset private zone", () => __awaiter(void 0, void 0, void 0, function* () {
|
|
73
|
+
mock.onPut(`${BASE_URL}/set-private-zone`).reply(200, "Success!");
|
|
74
|
+
const privateZoneArgs = Object.assign(Object.assign({}, args), { isPrivateZone: true, isPrivateZoneChatDisabled: false, privateZoneUserCap: 10 });
|
|
75
|
+
yield testDroppedAsset.updatePrivateZone(privateZoneArgs);
|
|
76
|
+
expect(mock.history.put.length).toBe(1);
|
|
77
|
+
}));
|
|
78
|
+
it("should update dropped asset scale", () => __awaiter(void 0, void 0, void 0, function* () {
|
|
79
|
+
mock.onPut(`${BASE_URL}/change-scale`).reply(200, "Success!");
|
|
80
|
+
yield testDroppedAsset.updateScale(75);
|
|
81
|
+
expect(mock.history.put.length).toBe(1);
|
|
82
|
+
}));
|
|
83
|
+
it("should update dropped asset uploaded media selected", () => __awaiter(void 0, void 0, void 0, function* () {
|
|
84
|
+
mock.onPut(`${BASE_URL}/change-uploaded-media-selected`).reply(200, "Success!");
|
|
85
|
+
yield testDroppedAsset.updateUploadedMediaSelected("abc123");
|
|
86
|
+
expect(mock.history.put.length).toBe(1);
|
|
87
|
+
}));
|
|
88
|
+
it("should update dropped asset web image layers", () => __awaiter(void 0, void 0, void 0, function* () {
|
|
89
|
+
mock.onPut(`${BASE_URL}/set-webimage-layers`).reply(200, "Success!");
|
|
90
|
+
yield testDroppedAsset.updateWebImageLayers("test", "test");
|
|
91
|
+
expect(mock.history.put.length).toBe(1);
|
|
92
|
+
}));
|
|
93
|
+
});
|
|
@@ -0,0 +1,23 @@
|
|
|
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 { scenes } from "__mocks__";
|
|
11
|
+
import { User } from "controllers";
|
|
12
|
+
afterEach(() => {
|
|
13
|
+
jest.resetAllMocks();
|
|
14
|
+
});
|
|
15
|
+
describe("User Class", () => {
|
|
16
|
+
it("should return an array of scenes owned by specific email address", () => __awaiter(void 0, void 0, void 0, function* () {
|
|
17
|
+
const testUser = yield new User({ apiKey: "key", email: "test@email.com" });
|
|
18
|
+
testUser.fetchScenesByEmail = jest.fn().mockReturnValue(scenes);
|
|
19
|
+
const mockScenes = yield testUser.fetchScenesByEmail();
|
|
20
|
+
expect(testUser.fetchScenesByEmail).toHaveBeenCalled();
|
|
21
|
+
expect(mockScenes).toBeDefined();
|
|
22
|
+
}));
|
|
23
|
+
});
|
|
@@ -0,0 +1,24 @@
|
|
|
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 { Visitor } from "controllers";
|
|
11
|
+
import { visitor } from "../../__mocks__/visitors";
|
|
12
|
+
afterEach(() => {
|
|
13
|
+
jest.resetAllMocks();
|
|
14
|
+
});
|
|
15
|
+
describe("Visitor Class", () => {
|
|
16
|
+
it("should create an instance of Visitor", () => __awaiter(void 0, void 0, void 0, function* () {
|
|
17
|
+
const testVisitor = new Visitor({
|
|
18
|
+
apiKey: "key",
|
|
19
|
+
args: visitor,
|
|
20
|
+
urlSlug: "magic",
|
|
21
|
+
});
|
|
22
|
+
expect(testVisitor.playerId).toEqual(1);
|
|
23
|
+
}));
|
|
24
|
+
});
|