2021-07-23 14:59:56 +02:00
|
|
|
import "jasmine";
|
|
|
|
import { Room } from "../../../src/Connexion/Room";
|
2020-11-18 18:15:57 +01:00
|
|
|
|
2021-07-23 14:59:56 +02:00
|
|
|
describe("Room getIdFromIdentifier()", () => {
|
|
|
|
it("should work with an absolute room id and no hash as parameter", () => {
|
|
|
|
const { roomId, hash } = Room.getIdFromIdentifier("/_/global/maps.workadventu.re/test2.json", "", "");
|
|
|
|
expect(roomId).toEqual("_/global/maps.workadventu.re/test2.json");
|
2021-06-23 12:42:24 +02:00
|
|
|
expect(hash).toEqual(null);
|
2020-11-18 18:15:57 +01:00
|
|
|
});
|
2021-07-23 14:59:56 +02:00
|
|
|
it("should work with an absolute room id and a hash as parameters", () => {
|
|
|
|
const { roomId, hash } = Room.getIdFromIdentifier("/_/global/maps.workadventu.re/test2.json#start", "", "");
|
|
|
|
expect(roomId).toEqual("_/global/maps.workadventu.re/test2.json");
|
|
|
|
expect(hash).toEqual("start");
|
2020-11-18 18:15:57 +01:00
|
|
|
});
|
2021-07-23 14:59:56 +02:00
|
|
|
it("should work with an absolute room id, regardless of baseUrl or instance", () => {
|
2021-07-02 18:49:22 +02:00
|
|
|
const { roomId, hash } = Room.getIdFromIdentifier(
|
2021-07-23 14:59:56 +02:00
|
|
|
"/_/global/maps.workadventu.re/test2.json",
|
|
|
|
"https://another.domain/_/global/test.json",
|
|
|
|
"lol"
|
2021-07-02 18:49:22 +02:00
|
|
|
);
|
2021-07-23 14:59:56 +02:00
|
|
|
expect(roomId).toEqual("_/global/maps.workadventu.re/test2.json");
|
2021-06-23 12:42:24 +02:00
|
|
|
expect(hash).toEqual(null);
|
2020-11-18 18:15:57 +01:00
|
|
|
});
|
2021-06-23 12:42:24 +02:00
|
|
|
|
2021-07-23 14:59:56 +02:00
|
|
|
it("should work with a relative file link and no hash as parameters", () => {
|
2021-07-02 18:49:22 +02:00
|
|
|
const { roomId, hash } = Room.getIdFromIdentifier(
|
2021-07-23 14:59:56 +02:00
|
|
|
"./test2.json",
|
|
|
|
"https://maps.workadventu.re/test.json",
|
|
|
|
"global"
|
2021-07-02 18:49:22 +02:00
|
|
|
);
|
2021-07-23 14:59:56 +02:00
|
|
|
expect(roomId).toEqual("_/global/maps.workadventu.re/test2.json");
|
2021-06-23 12:42:24 +02:00
|
|
|
expect(hash).toEqual(null);
|
2020-11-18 18:15:57 +01:00
|
|
|
});
|
2021-07-23 14:59:56 +02:00
|
|
|
it("should work with a relative file link with no dot", () => {
|
2021-07-02 18:49:22 +02:00
|
|
|
const { roomId, hash } = Room.getIdFromIdentifier(
|
2021-07-23 14:59:56 +02:00
|
|
|
"test2.json",
|
|
|
|
"https://maps.workadventu.re/test.json",
|
|
|
|
"global"
|
2021-07-02 18:49:22 +02:00
|
|
|
);
|
2021-07-23 14:59:56 +02:00
|
|
|
expect(roomId).toEqual("_/global/maps.workadventu.re/test2.json");
|
2021-06-23 12:42:24 +02:00
|
|
|
expect(hash).toEqual(null);
|
2020-11-18 18:15:57 +01:00
|
|
|
});
|
2021-07-23 14:59:56 +02:00
|
|
|
it("should work with a relative file link two levels deep", () => {
|
2021-07-02 18:49:22 +02:00
|
|
|
const { roomId, hash } = Room.getIdFromIdentifier(
|
2021-07-23 14:59:56 +02:00
|
|
|
"../floor1/Floor1.json",
|
|
|
|
"https://maps.workadventu.re/floor0/Floor0.json",
|
|
|
|
"global"
|
2021-07-02 18:49:22 +02:00
|
|
|
);
|
2021-07-23 14:59:56 +02:00
|
|
|
expect(roomId).toEqual("_/global/maps.workadventu.re/floor1/Floor1.json");
|
2021-06-23 12:42:24 +02:00
|
|
|
expect(hash).toEqual(null);
|
2020-11-18 18:15:57 +01:00
|
|
|
});
|
2021-07-23 14:59:56 +02:00
|
|
|
it("should work with a relative file link that rewrite the map domain", () => {
|
2021-07-02 18:49:22 +02:00
|
|
|
const { roomId, hash } = Room.getIdFromIdentifier(
|
2021-07-23 14:59:56 +02:00
|
|
|
"../../maps.workadventure.localhost/Floor1/floor1.json",
|
|
|
|
"https://maps.workadventu.re/floor0/Floor0.json",
|
|
|
|
"global"
|
2021-07-02 18:49:22 +02:00
|
|
|
);
|
2021-07-23 14:59:56 +02:00
|
|
|
expect(roomId).toEqual("_/global/maps.workadventure.localhost/Floor1/floor1.json");
|
2021-06-23 12:42:24 +02:00
|
|
|
expect(hash).toEqual(null);
|
2021-01-05 17:08:33 +01:00
|
|
|
});
|
2021-07-23 14:59:56 +02:00
|
|
|
it("should work with a relative file link that rewrite the map instance", () => {
|
2021-07-02 18:49:22 +02:00
|
|
|
const { roomId, hash } = Room.getIdFromIdentifier(
|
2021-07-23 14:59:56 +02:00
|
|
|
"../../../notglobal/maps.workadventu.re/Floor1/floor1.json",
|
|
|
|
"https://maps.workadventu.re/floor0/Floor0.json",
|
|
|
|
"global"
|
2021-07-02 18:49:22 +02:00
|
|
|
);
|
2021-07-23 14:59:56 +02:00
|
|
|
expect(roomId).toEqual("_/notglobal/maps.workadventu.re/Floor1/floor1.json");
|
2021-06-23 12:42:24 +02:00
|
|
|
expect(hash).toEqual(null);
|
2021-01-05 17:08:33 +01:00
|
|
|
});
|
2021-07-23 14:59:56 +02:00
|
|
|
it("should work with a relative file link that change the map type", () => {
|
2021-07-02 18:49:22 +02:00
|
|
|
const { roomId, hash } = Room.getIdFromIdentifier(
|
2021-07-23 14:59:56 +02:00
|
|
|
"../../../../@/tcm/is/great",
|
|
|
|
"https://maps.workadventu.re/floor0/Floor0.json",
|
|
|
|
"global"
|
2021-07-02 18:49:22 +02:00
|
|
|
);
|
2021-07-23 14:59:56 +02:00
|
|
|
expect(roomId).toEqual("@/tcm/is/great");
|
2021-06-23 12:42:24 +02:00
|
|
|
expect(hash).toEqual(null);
|
2021-01-05 17:08:33 +01:00
|
|
|
});
|
2021-06-23 12:42:24 +02:00
|
|
|
|
2021-07-23 14:59:56 +02:00
|
|
|
it("should work with a relative file link and a hash as parameters", () => {
|
2021-07-02 18:49:22 +02:00
|
|
|
const { roomId, hash } = Room.getIdFromIdentifier(
|
2021-07-23 14:59:56 +02:00
|
|
|
"./test2.json#start",
|
|
|
|
"https://maps.workadventu.re/test.json",
|
|
|
|
"global"
|
2021-07-02 18:49:22 +02:00
|
|
|
);
|
2021-07-23 14:59:56 +02:00
|
|
|
expect(roomId).toEqual("_/global/maps.workadventu.re/test2.json");
|
|
|
|
expect(hash).toEqual("start");
|
2020-11-18 18:15:57 +01:00
|
|
|
});
|
2021-07-02 18:49:22 +02:00
|
|
|
});
|