@rtsdk/topia 0.0.8 → 0.0.9

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 +9 -9
  6. package/dist/controllers/Asset.js +62 -0
  7. package/dist/controllers/DroppedAsset.js +150 -0
  8. package/dist/controllers/Scene.js +22 -0
  9. package/dist/controllers/Visitor.js +70 -0
  10. package/dist/controllers/World.js +125 -110
  11. package/dist/controllers/__tests__/asset.test.js +14 -0
  12. package/dist/controllers/__tests__/droppedAsset.test.js +109 -0
  13. package/dist/controllers/__tests__/scene.test.js +14 -0
  14. package/dist/controllers/__tests__/visitor.test.js +12 -0
  15. package/dist/controllers/__tests__/world.test.js +48 -109
  16. package/dist/controllers/index.js +4 -0
  17. package/dist/index.js +448 -125
  18. package/dist/{types/Visitor.js → interfaces/DroppedAssetInterfaces.js} +0 -0
  19. package/dist/interfaces/WorldInterfaces.js +1 -0
  20. package/dist/interfaces/index.js +2 -0
  21. package/dist/types/DroppedAssetType.js +1 -0
  22. package/dist/types/DroppedAssetTypes.js +12 -0
  23. package/dist/types/VisitorType.js +1 -0
  24. package/dist/types/VisitorTypes.js +1 -0
  25. package/dist/types/Visitors.js +1 -0
  26. package/dist/types/index.js +2 -1
  27. package/dist/utils/__tests__/scatterVisitors.test.js +11 -0
  28. package/dist/utils/createDroppedAsset.js +72 -0
  29. package/dist/utils/createVisitor.js +3 -0
  30. package/dist/utils/getErrorMessage.js +5 -0
  31. package/dist/utils/index.js +4 -0
  32. package/dist/utils/publicAPI.js +11 -0
  33. package/dist/utils/scatterVisitors.js +5 -0
  34. package/package.json +3 -1
@@ -1,111 +1,50 @@
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 __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
- };
37
1
  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
- }
77
- });
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
- }
109
- });
110
- }); });
2
+ import { Visitor, World } from "../../controllers";
3
+ import axios from "axios";
4
+ import MockAdapter from "axios-mock-adapter";
5
+ import { createVisitor } from "utils";
6
+ const BASE_URL = "https://api.topia.io/api/world/magic";
7
+ describe("World Class", () => {
8
+ let mock;
9
+ beforeAll(() => {
10
+ mock = new MockAdapter(axios);
11
+ });
12
+ afterEach(() => {
13
+ mock.reset();
14
+ jest.resetAllMocks();
15
+ });
16
+ it("should return details of a world", async () => {
17
+ const testWorld = await new World("key", "magic");
18
+ expect(testWorld.urlSlug).toEqual("magic");
19
+ testWorld.fetchDetails = jest.fn().mockReturnValue(worlds[1]);
20
+ const mockDetails = await testWorld.fetchDetails();
21
+ expect(testWorld.fetchDetails).toHaveBeenCalled();
22
+ expect(mockDetails).toBeDefined();
23
+ });
24
+ it("should move all visitors within a world to a single set of coordinates", async () => {
25
+ mock.onGet(`${BASE_URL}/visitors`).reply(200, visitors);
26
+ mock.onPut(`${BASE_URL}/visitors/1/move`).reply(200, "Success!");
27
+ const testWorld = await new World("key", "magic");
28
+ const args = { shouldFetchVisitors: true, shouldTeleportVisitors: true, scatterVisitorsBy: 100, x: 20, y: 40 };
29
+ await testWorld.moveAllVisitors(args);
30
+ expect(mock.history.put.length).toBe(Object.keys(visitors).length);
31
+ });
32
+ it("should return success if world doesn't have visitors", async () => {
33
+ const testWorld = await new World("key", "magic");
34
+ const args = { shouldFetchVisitors: false, scatterVisitorsBy: 100, x: 20, y: 40 };
35
+ await testWorld.moveAllVisitors(args);
36
+ expect(mock.history.put.length).toBe(0);
37
+ });
38
+ it("should move a list of visitors to uniquely specified coordinates", async () => {
39
+ mock.onPut(`${BASE_URL}/visitors/1/move`).reply(200, "Success!");
40
+ const testWorld = await new World("key", "magic");
41
+ const v1 = createVisitor(Visitor, "key", visitors["1"], "magic");
42
+ const v2 = createVisitor(Visitor, "key", visitors["2"], "magic");
43
+ const testVisitors = [
44
+ { visitorObj: v1, shouldTeleportVisitor: true, x: 0, y: 0 },
45
+ { visitorObj: v2, shouldTeleportVisitor: false, x: 100, y: 100 },
46
+ ];
47
+ await testWorld.moveVisitors(testVisitors);
48
+ expect(mock.history.put.length).toBe(2);
49
+ });
111
50
  });
@@ -1 +1,5 @@
1
+ export { Asset } from "./Asset";
2
+ export { DroppedAsset } from "./DroppedAsset";
3
+ export { Scene } from "./Scene";
4
+ export { Visitor } from "./Visitor";
1
5
  export { World } from "./World";