@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
|
@@ -7,105 +7,69 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
|
|
|
7
7
|
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
8
8
|
});
|
|
9
9
|
};
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
|
|
13
|
-
function verb(n) { return function (v) { return step([n, v]); }; }
|
|
14
|
-
function step(op) {
|
|
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
|
-
}
|
|
36
|
-
};
|
|
10
|
+
import axios from "axios";
|
|
11
|
+
import MockAdapter from "axios-mock-adapter";
|
|
37
12
|
import { visitors, worlds } from "../../__mocks__";
|
|
38
|
-
import { World } from "
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
})
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
13
|
+
import { Visitor, World } from "controllers";
|
|
14
|
+
const BASE_URL = "https://api.topia.io/api/world/magic";
|
|
15
|
+
const apiKey = "key";
|
|
16
|
+
const args = worlds[1];
|
|
17
|
+
const urlSlug = worlds[1].urlSlug;
|
|
18
|
+
describe("World Class", () => {
|
|
19
|
+
let mock, testWorld;
|
|
20
|
+
beforeEach(() => {
|
|
21
|
+
mock = new MockAdapter(axios);
|
|
22
|
+
testWorld = new World({ apiKey, args, urlSlug });
|
|
23
|
+
});
|
|
24
|
+
afterEach(() => {
|
|
25
|
+
mock.restore();
|
|
26
|
+
jest.resetAllMocks();
|
|
27
|
+
});
|
|
28
|
+
it("should return details of a world", () => __awaiter(void 0, void 0, void 0, function* () {
|
|
29
|
+
expect(testWorld.urlSlug).toEqual("magic");
|
|
30
|
+
testWorld.fetchDetails = jest.fn().mockReturnValue(worlds[1]);
|
|
31
|
+
const mockDetails = yield testWorld.fetchDetails();
|
|
32
|
+
expect(testWorld.fetchDetails).toHaveBeenCalled();
|
|
33
|
+
expect(mockDetails).toBeDefined();
|
|
34
|
+
}));
|
|
35
|
+
it("should update details of a world", () => __awaiter(void 0, void 0, void 0, function* () {
|
|
36
|
+
mock.onPut(`${BASE_URL}/world-details`).reply(200, "Success!");
|
|
37
|
+
const worldArgs = Object.assign(Object.assign({}, args), { controls: {
|
|
38
|
+
allowMuteAll: false,
|
|
39
|
+
}, description: "testing update details", name: "magic" });
|
|
40
|
+
yield testWorld.updateDetails(worldArgs);
|
|
41
|
+
expect(mock.history.put.length).toBe(1);
|
|
42
|
+
expect(testWorld.urlSlug).toEqual("magic");
|
|
43
|
+
}));
|
|
44
|
+
it("should move all visitors within a world to a single set of coordinates", () => __awaiter(void 0, void 0, void 0, function* () {
|
|
45
|
+
mock.onGet(`${BASE_URL}/visitors`).reply(200, visitors);
|
|
46
|
+
mock.onPut(`${BASE_URL}/visitors/1/move`).reply(200, "Success!");
|
|
47
|
+
const args = { shouldFetchVisitors: true, shouldTeleportVisitors: true, scatterVisitorsBy: 100, x: 20, y: 40 };
|
|
48
|
+
yield testWorld.moveAllVisitors(args);
|
|
49
|
+
expect(mock.history.put.length).toBe(Object.keys(visitors).length);
|
|
50
|
+
}));
|
|
51
|
+
it("should return success if world doesn't have visitors", () => __awaiter(void 0, void 0, void 0, function* () {
|
|
52
|
+
const args = { shouldFetchVisitors: false, scatterVisitorsBy: 100, x: 20, y: 40 };
|
|
53
|
+
yield testWorld.moveAllVisitors(args);
|
|
54
|
+
expect(mock.history.put.length).toBe(0);
|
|
55
|
+
}));
|
|
56
|
+
it("should move a list of visitors to uniquely specified coordinates", () => __awaiter(void 0, void 0, void 0, function* () {
|
|
57
|
+
mock.onPut(`${BASE_URL}/visitors/1/move`).reply(200, "Success!");
|
|
58
|
+
const v1 = new Visitor({
|
|
59
|
+
apiKey,
|
|
60
|
+
args: visitors["1"],
|
|
61
|
+
urlSlug,
|
|
77
62
|
});
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
switch (_a.label) {
|
|
83
|
-
case 0: return [4 /*yield*/, new World("key", "lina")];
|
|
84
|
-
case 1:
|
|
85
|
-
testWorld = _a.sent();
|
|
86
|
-
testWorld.moveVisitors = jest.fn();
|
|
87
|
-
visitors = [
|
|
88
|
-
{
|
|
89
|
-
id: "1",
|
|
90
|
-
coordinates: {
|
|
91
|
-
x: 100,
|
|
92
|
-
y: 100
|
|
93
|
-
}
|
|
94
|
-
},
|
|
95
|
-
{
|
|
96
|
-
id: "2",
|
|
97
|
-
coordinates: {
|
|
98
|
-
x: 200,
|
|
99
|
-
y: 200
|
|
100
|
-
}
|
|
101
|
-
},
|
|
102
|
-
];
|
|
103
|
-
return [4 /*yield*/, testWorld.moveVisitors(visitors)];
|
|
104
|
-
case 2:
|
|
105
|
-
_a.sent();
|
|
106
|
-
expect(testWorld.moveVisitors).toHaveBeenCalled();
|
|
107
|
-
return [2 /*return*/];
|
|
108
|
-
}
|
|
63
|
+
const v2 = new Visitor({
|
|
64
|
+
apiKey,
|
|
65
|
+
args: visitors["2"],
|
|
66
|
+
urlSlug,
|
|
109
67
|
});
|
|
110
|
-
|
|
68
|
+
const testVisitors = [
|
|
69
|
+
{ visitorObj: v1, shouldTeleportVisitor: true, x: 0, y: 0 },
|
|
70
|
+
{ visitorObj: v2, shouldTeleportVisitor: false, x: 100, y: 100 },
|
|
71
|
+
];
|
|
72
|
+
yield testWorld.moveVisitors(testVisitors);
|
|
73
|
+
expect(mock.history.put.length).toBe(2);
|
|
74
|
+
}));
|
|
111
75
|
});
|