@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.
Files changed (34) hide show
  1. package/dist/__mocks__/assets.js +241 -0
  2. package/dist/__mocks__/index.js +2 -0
  3. package/dist/__mocks__/scenes.js +104 -0
  4. package/dist/__mocks__/visitors.js +43 -16
  5. package/dist/__mocks__/worlds.js +10 -9
  6. package/dist/controllers/Asset.js +20 -0
  7. package/dist/controllers/DroppedAsset.js +151 -0
  8. package/dist/controllers/User.js +63 -0
  9. package/dist/controllers/Visitor.js +31 -0
  10. package/dist/controllers/World.js +165 -101
  11. package/dist/controllers/__tests__/asset.test.js +23 -0
  12. package/dist/controllers/__tests__/droppedAsset.test.js +93 -0
  13. package/dist/controllers/__tests__/user.test.js +23 -0
  14. package/dist/controllers/__tests__/visitor.test.js +24 -0
  15. package/dist/controllers/__tests__/world.test.js +62 -98
  16. package/dist/controllers/index.js +4 -0
  17. package/dist/index.js +464 -126
  18. package/dist/{types/Visitor.js → interfaces/AssetInterfaces.js} +0 -0
  19. package/dist/interfaces/DroppedAssetInterfaces.js +1 -0
  20. package/dist/interfaces/VisitorInterfaces.js +1 -0
  21. package/dist/interfaces/WorldInterfaces.js +1 -0
  22. package/dist/interfaces/index.js +4 -0
  23. package/dist/types/DroppedAssetTypes.js +12 -0
  24. package/dist/types/VisitorTypes.js +1 -0
  25. package/dist/types/index.js +2 -1
  26. package/dist/utils/__tests__/removeUndefined.test.js +10 -0
  27. package/dist/utils/__tests__/scatterVisitors.test.js +11 -0
  28. package/dist/utils/createDroppedAsset.js +72 -0
  29. package/dist/utils/getErrorMessage.js +5 -0
  30. package/dist/utils/index.js +4 -0
  31. package/dist/utils/publicAPI.js +10 -0
  32. package/dist/utils/removeUndefined.js +8 -0
  33. package/dist/utils/scatterVisitors.js +5 -0
  34. 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
- var __generator = (this && this.__generator) || function (thisArg, body) {
11
- var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
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 "../../controllers";
39
- afterEach(function () {
40
- jest.resetAllMocks();
41
- });
42
- describe("get world details", function () {
43
- it("should return details of a world", function () { return __awaiter(void 0, void 0, void 0, function () {
44
- var testWorld, mockDetails;
45
- return __generator(this, function (_a) {
46
- switch (_a.label) {
47
- case 0: return [4 /*yield*/, new World("key", "lina")];
48
- case 1:
49
- testWorld = _a.sent();
50
- testWorld.fetchDetails = jest.fn().mockReturnValue(worlds[1]);
51
- return [4 /*yield*/, testWorld.fetchDetails()];
52
- case 2:
53
- mockDetails = _a.sent();
54
- expect(testWorld.fetchDetails).toHaveBeenCalled();
55
- expect(mockDetails).toBeDefined();
56
- return [2 /*return*/];
57
- }
58
- });
59
- }); });
60
- });
61
- describe("get and move visitors", function () {
62
- it("should return a list of current visitors for a given world", function () { return __awaiter(void 0, void 0, void 0, function () {
63
- var testWorld, mockVisitors;
64
- return __generator(this, function (_a) {
65
- switch (_a.label) {
66
- case 0: return [4 /*yield*/, new World("key", "lina")];
67
- case 1:
68
- testWorld = _a.sent();
69
- testWorld.fetchVisitors = jest.fn().mockReturnValue(visitors);
70
- return [4 /*yield*/, testWorld.fetchVisitors()];
71
- case 2:
72
- mockVisitors = _a.sent();
73
- expect(testWorld.fetchVisitors).toHaveBeenCalled();
74
- expect(mockVisitors).toBeDefined();
75
- return [2 /*return*/];
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
- it("should move a visitor to specified coordinates", function () { return __awaiter(void 0, void 0, void 0, function () {
80
- var testWorld, visitors;
81
- return __generator(this, function (_a) {
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
  });
@@ -1 +1,5 @@
1
+ export { Asset } from "./Asset";
2
+ export { DroppedAsset } from "./DroppedAsset";
3
+ export { User } from "./User";
4
+ export { Visitor } from "./Visitor";
1
5
  export { World } from "./World";