@rtsdk/topia 0.0.9 → 0.0.11

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.
@@ -1,109 +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
+ };
1
10
  import { droppedAssets } from "__mocks__";
2
11
  import { DroppedAsset } from "..";
3
12
  import { DroppedAssetClickType, DroppedAssetMediaType } from "../../types/DroppedAssetTypes";
4
13
  import axios from "axios";
5
14
  import MockAdapter from "axios-mock-adapter";
6
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";
7
20
  describe("DroppedAsset Class", () => {
8
- let mock;
9
- beforeAll(() => {
21
+ let mock, testDroppedAsset;
22
+ beforeEach(() => {
10
23
  mock = new MockAdapter(axios);
24
+ testDroppedAsset = new DroppedAsset({ apiKey, id, args, urlSlug });
11
25
  });
12
26
  afterEach(() => {
13
- mock.reset();
27
+ mock.restore();
14
28
  jest.resetAllMocks();
15
29
  });
16
- it("should fetch dropped asset by id", async () => {
17
- const testDroppedAsset = new DroppedAsset("key", { id: droppedAssets[0].id }, "", "magic");
30
+ it("should fetch dropped asset by id", () => __awaiter(void 0, void 0, void 0, function* () {
18
31
  testDroppedAsset.fetchDroppedAssetById = jest.fn().mockReturnValue(droppedAssets[0]);
19
- const mockDroppedAssets = await testDroppedAsset.fetchDroppedAssetById();
32
+ const mockDroppedAssets = yield testDroppedAsset.fetchDroppedAssetById();
20
33
  expect(testDroppedAsset.fetchDroppedAssetById).toHaveBeenCalled();
21
34
  expect(mockDroppedAssets).toBeDefined();
22
- });
23
- it("should update dropped asset broadcast zone", async () => {
35
+ }));
36
+ it("should update dropped asset broadcast zone", () => __awaiter(void 0, void 0, void 0, function* () {
24
37
  mock.onPut(`${BASE_URL}/set-asset-broadcast`).reply(200, "Success!");
25
- const testDroppedAsset = new DroppedAsset("key", { id: droppedAssets[0].id }, "", "magic");
26
- const args = {
27
- assetBroadcast: true,
28
- assetBroadcastAll: false,
29
- broadcasterEmail: "test@test.com",
30
- };
31
- await testDroppedAsset.updateBroadcast(args);
38
+ const broadcastArgs = Object.assign(Object.assign({}, args), { assetBroadcast: true, assetBroadcastAll: false, broadcasterEmail: "test@test.com" });
39
+ yield testDroppedAsset.updateBroadcast(broadcastArgs);
32
40
  expect(mock.history.put.length).toBe(1);
33
- });
34
- it("should update dropped asset click type", async () => {
41
+ }));
42
+ it("should update dropped asset click type", () => __awaiter(void 0, void 0, void 0, function* () {
35
43
  mock.onPut(`${BASE_URL}/change-click-type`).reply(200, "Success!");
36
- const testDroppedAsset = new DroppedAsset("key", { id: droppedAssets[0].id }, "", "magic");
37
- const args = {
38
- clickType: DroppedAssetClickType.LINK,
39
- clickableLink: "www.test.com",
40
- clickableLinkTitle: "Test",
41
- portalName: "Test",
42
- position: {
44
+ const clickTypeArgs = Object.assign(Object.assign({}, args), { clickType: DroppedAssetClickType.LINK, clickableLink: "www.test.com", clickableLinkTitle: "Test", portalName: "Test", position: {
43
45
  x: 0,
44
46
  y: 0,
45
- },
46
- };
47
- await testDroppedAsset.updateClickType(args);
47
+ } });
48
+ yield testDroppedAsset.updateClickType(clickTypeArgs);
48
49
  expect(mock.history.put.length).toBe(1);
49
- });
50
- it("should update dropped asset custom text", async () => {
50
+ }));
51
+ it("should update dropped asset custom text", () => __awaiter(void 0, void 0, void 0, function* () {
51
52
  mock.onPut(`${BASE_URL}/set-custom-text`).reply(200, "Success!");
52
- const testDroppedAsset = new DroppedAsset("key", { id: droppedAssets[0].id }, "", "magic");
53
- await testDroppedAsset.updateCustomText({ textColor: "#abc123" }, "hello world");
53
+ yield testDroppedAsset.updateCustomText({ textColor: "#abc123" }, "hello world");
54
54
  expect(mock.history.put.length).toBe(1);
55
- });
56
- it("should update dropped asset media type", async () => {
55
+ }));
56
+ it("should update dropped asset media type", () => __awaiter(void 0, void 0, void 0, function* () {
57
57
  mock.onPut(`${BASE_URL}/change-media-type`).reply(200, "Success!");
58
- const args = {
59
- audioRadius: 0,
60
- audioVolume: -1,
61
- isVideo: true,
62
- mediaLink: "https://www.youtube.com/watch?v=dQw4w9WgXcQ",
63
- mediaName: "string",
64
- mediaType: DroppedAssetMediaType.LINK,
65
- portalName: "community",
66
- syncUserMedia: true,
67
- };
68
- const testDroppedAsset = new DroppedAsset("key", { id: droppedAssets[0].id }, "", "magic");
69
- await testDroppedAsset.updateMediaType(args);
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);
70
60
  expect(mock.history.put.length).toBe(1);
71
- });
72
- it("should update dropped asset mute zone", async () => {
61
+ }));
62
+ it("should update dropped asset mute zone", () => __awaiter(void 0, void 0, void 0, function* () {
73
63
  mock.onPut(`${BASE_URL}/set-mute-zone`).reply(200, "Success!");
74
- const testDroppedAsset = new DroppedAsset("key", { id: droppedAssets[0].id }, "", "magic");
75
- await testDroppedAsset.updateMuteZone(true);
64
+ yield testDroppedAsset.updateMuteZone(true);
76
65
  expect(mock.history.put.length).toBe(1);
77
- });
78
- it("should update dropped asset position", async () => {
66
+ }));
67
+ it("should update dropped asset position", () => __awaiter(void 0, void 0, void 0, function* () {
79
68
  mock.onPut(`${BASE_URL}/set-position`).reply(200, "Success!");
80
- const testDroppedAsset = new DroppedAsset("key", { id: droppedAssets[0].id }, "", "magic");
81
- await testDroppedAsset.updatePosition(100, 100);
69
+ yield testDroppedAsset.updatePosition(100, 100);
82
70
  expect(mock.history.put.length).toBe(1);
83
- });
84
- it("should update dropped asset private zone", async () => {
71
+ }));
72
+ it("should update dropped asset private zone", () => __awaiter(void 0, void 0, void 0, function* () {
85
73
  mock.onPut(`${BASE_URL}/set-private-zone`).reply(200, "Success!");
86
- const args = { isPrivateZone: true, isPrivateZoneChatDisabled: false, privateZoneUserCap: 10 };
87
- const testDroppedAsset = new DroppedAsset("key", { id: droppedAssets[0].id }, "", "magic");
88
- await testDroppedAsset.updatePrivateZone(args);
74
+ const privateZoneArgs = Object.assign(Object.assign({}, args), { isPrivateZone: true, isPrivateZoneChatDisabled: false, privateZoneUserCap: 10 });
75
+ yield testDroppedAsset.updatePrivateZone(privateZoneArgs);
89
76
  expect(mock.history.put.length).toBe(1);
90
- });
91
- it("should update dropped asset scale", async () => {
77
+ }));
78
+ it("should update dropped asset scale", () => __awaiter(void 0, void 0, void 0, function* () {
92
79
  mock.onPut(`${BASE_URL}/change-scale`).reply(200, "Success!");
93
- const testDroppedAsset = new DroppedAsset("key", { id: droppedAssets[0].id }, "", "magic");
94
- await testDroppedAsset.updateScale(75);
80
+ yield testDroppedAsset.updateScale(75);
95
81
  expect(mock.history.put.length).toBe(1);
96
- });
97
- it("should update dropped asset uploaded media selected", async () => {
82
+ }));
83
+ it("should update dropped asset uploaded media selected", () => __awaiter(void 0, void 0, void 0, function* () {
98
84
  mock.onPut(`${BASE_URL}/change-uploaded-media-selected`).reply(200, "Success!");
99
- const testDroppedAsset = new DroppedAsset("key", { id: droppedAssets[0].id }, "", "magic");
100
- await testDroppedAsset.updateUploadedMediaSelected("abc123");
85
+ yield testDroppedAsset.updateUploadedMediaSelected("abc123");
101
86
  expect(mock.history.put.length).toBe(1);
102
- });
103
- it("should update dropped asset web image layers", async () => {
87
+ }));
88
+ it("should update dropped asset web image layers", () => __awaiter(void 0, void 0, void 0, function* () {
104
89
  mock.onPut(`${BASE_URL}/set-webimage-layers`).reply(200, "Success!");
105
- const testDroppedAsset = new DroppedAsset("key", { id: droppedAssets[0].id }, "", "magic");
106
- await testDroppedAsset.updateWebImageLayers("test", "test");
90
+ yield testDroppedAsset.updateWebImageLayers("test", "test");
107
91
  expect(mock.history.put.length).toBe(1);
108
- });
92
+ }));
109
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
+ });
@@ -1,12 +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
+ };
1
10
  import { Visitor } from "controllers";
2
- import { createVisitor } from "../../utils/createVisitor";
3
11
  import { visitor } from "../../__mocks__/visitors";
4
12
  afterEach(() => {
5
13
  jest.resetAllMocks();
6
14
  });
7
15
  describe("Visitor Class", () => {
8
- it("should create an instance of Visitor", async () => {
9
- const testVisitor = createVisitor(Visitor, "apiKey", visitor, "magic");
10
- expect(testVisitor.displayName).toEqual("test");
11
- });
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
+ }));
12
24
  });
@@ -1,50 +1,75 @@
1
- import { visitors, worlds } from "../../__mocks__";
2
- import { Visitor, World } from "../../controllers";
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
+ };
3
10
  import axios from "axios";
4
11
  import MockAdapter from "axios-mock-adapter";
5
- import { createVisitor } from "utils";
12
+ import { visitors, worlds } from "../../__mocks__";
13
+ import { Visitor, World } from "controllers";
6
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;
7
18
  describe("World Class", () => {
8
- let mock;
9
- beforeAll(() => {
19
+ let mock, testWorld;
20
+ beforeEach(() => {
10
21
  mock = new MockAdapter(axios);
22
+ testWorld = new World({ apiKey, args, urlSlug });
11
23
  });
12
24
  afterEach(() => {
13
- mock.reset();
25
+ mock.restore();
14
26
  jest.resetAllMocks();
15
27
  });
16
- it("should return details of a world", async () => {
17
- const testWorld = await new World("key", "magic");
28
+ it("should return details of a world", () => __awaiter(void 0, void 0, void 0, function* () {
18
29
  expect(testWorld.urlSlug).toEqual("magic");
19
30
  testWorld.fetchDetails = jest.fn().mockReturnValue(worlds[1]);
20
- const mockDetails = await testWorld.fetchDetails();
31
+ const mockDetails = yield testWorld.fetchDetails();
21
32
  expect(testWorld.fetchDetails).toHaveBeenCalled();
22
33
  expect(mockDetails).toBeDefined();
23
- });
24
- it("should move all visitors within a world to a single set of coordinates", async () => {
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* () {
25
45
  mock.onGet(`${BASE_URL}/visitors`).reply(200, visitors);
26
46
  mock.onPut(`${BASE_URL}/visitors/1/move`).reply(200, "Success!");
27
- const testWorld = await new World("key", "magic");
28
47
  const args = { shouldFetchVisitors: true, shouldTeleportVisitors: true, scatterVisitorsBy: 100, x: 20, y: 40 };
29
- await testWorld.moveAllVisitors(args);
48
+ yield testWorld.moveAllVisitors(args);
30
49
  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");
50
+ }));
51
+ it("should return success if world doesn't have visitors", () => __awaiter(void 0, void 0, void 0, function* () {
34
52
  const args = { shouldFetchVisitors: false, scatterVisitorsBy: 100, x: 20, y: 40 };
35
- await testWorld.moveAllVisitors(args);
53
+ yield testWorld.moveAllVisitors(args);
36
54
  expect(mock.history.put.length).toBe(0);
37
- });
38
- it("should move a list of visitors to uniquely specified coordinates", async () => {
55
+ }));
56
+ it("should move a list of visitors to uniquely specified coordinates", () => __awaiter(void 0, void 0, void 0, function* () {
39
57
  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");
58
+ const v1 = new Visitor({
59
+ apiKey,
60
+ args: visitors["1"],
61
+ urlSlug,
62
+ });
63
+ const v2 = new Visitor({
64
+ apiKey,
65
+ args: visitors["2"],
66
+ urlSlug,
67
+ });
43
68
  const testVisitors = [
44
69
  { visitorObj: v1, shouldTeleportVisitor: true, x: 0, y: 0 },
45
70
  { visitorObj: v2, shouldTeleportVisitor: false, x: 100, y: 100 },
46
71
  ];
47
- await testWorld.moveVisitors(testVisitors);
72
+ yield testWorld.moveVisitors(testVisitors);
48
73
  expect(mock.history.put.length).toBe(2);
49
- });
74
+ }));
50
75
  });
@@ -1,5 +1,5 @@
1
1
  export { Asset } from "./Asset";
2
2
  export { DroppedAsset } from "./DroppedAsset";
3
- export { Scene } from "./Scene";
3
+ export { User } from "./User";
4
4
  export { Visitor } from "./Visitor";
5
5
  export { World } from "./World";