@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.
- 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 +9 -9
- package/dist/controllers/Asset.js +62 -0
- package/dist/controllers/DroppedAsset.js +150 -0
- package/dist/controllers/Scene.js +22 -0
- package/dist/controllers/Visitor.js +70 -0
- package/dist/controllers/World.js +125 -110
- package/dist/controllers/__tests__/asset.test.js +14 -0
- package/dist/controllers/__tests__/droppedAsset.test.js +109 -0
- package/dist/controllers/__tests__/scene.test.js +14 -0
- package/dist/controllers/__tests__/visitor.test.js +12 -0
- package/dist/controllers/__tests__/world.test.js +48 -109
- package/dist/controllers/index.js +4 -0
- package/dist/index.js +448 -125
- package/dist/{types/Visitor.js → interfaces/DroppedAssetInterfaces.js} +0 -0
- package/dist/interfaces/WorldInterfaces.js +1 -0
- package/dist/interfaces/index.js +2 -0
- package/dist/types/DroppedAssetType.js +1 -0
- package/dist/types/DroppedAssetTypes.js +12 -0
- package/dist/types/VisitorType.js +1 -0
- package/dist/types/VisitorTypes.js +1 -0
- package/dist/types/Visitors.js +1 -0
- package/dist/types/index.js +2 -1
- package/dist/utils/__tests__/scatterVisitors.test.js +11 -0
- package/dist/utils/createDroppedAsset.js +72 -0
- package/dist/utils/createVisitor.js +3 -0
- package/dist/utils/getErrorMessage.js +5 -0
- package/dist/utils/index.js +4 -0
- package/dist/utils/publicAPI.js +11 -0
- package/dist/utils/scatterVisitors.js +5 -0
- 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
|
-
|
|
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
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
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
|
});
|