1 | "use strict";
|
2 | import 'source-map-support/register';
|
3 | const ContentRepo = require("../../lib/content-repo");
|
4 | const testUtils = require("../test-utils");
|
5 |
|
6 | import expect from 'expect';
|
7 |
|
8 | describe("ContentRepo", function() {
|
9 | const baseUrl = "https://my.home.server";
|
10 |
|
11 | beforeEach(function() {
|
12 | testUtils.beforeEach(this);
|
13 | });
|
14 |
|
15 | describe("getHttpUriForMxc", function() {
|
16 | it("should do nothing to HTTP URLs when allowing direct links", function() {
|
17 | const httpUrl = "http://example.com/image.jpeg";
|
18 | expect(
|
19 | ContentRepo.getHttpUriForMxc(
|
20 | baseUrl, httpUrl, undefined, undefined, undefined, true,
|
21 | ),
|
22 | ).toEqual(httpUrl);
|
23 | });
|
24 |
|
25 | it("should return the empty string HTTP URLs by default", function() {
|
26 | const httpUrl = "http://example.com/image.jpeg";
|
27 | expect(ContentRepo.getHttpUriForMxc(baseUrl, httpUrl)).toEqual("");
|
28 | });
|
29 |
|
30 | it("should return a download URL if no width/height/resize are specified",
|
31 | function() {
|
32 | const mxcUri = "mxc://server.name/resourceid";
|
33 | expect(ContentRepo.getHttpUriForMxc(baseUrl, mxcUri)).toEqual(
|
34 | baseUrl + "/_matrix/media/r0/download/server.name/resourceid",
|
35 | );
|
36 | });
|
37 |
|
38 | it("should return the empty string for null input", function() {
|
39 | expect(ContentRepo.getHttpUriForMxc(null)).toEqual("");
|
40 | });
|
41 |
|
42 | it("should return a thumbnail URL if a width/height/resize is specified",
|
43 | function() {
|
44 | const mxcUri = "mxc://server.name/resourceid";
|
45 | expect(ContentRepo.getHttpUriForMxc(baseUrl, mxcUri, 32, 64, "crop")).toEqual(
|
46 | baseUrl + "/_matrix/media/r0/thumbnail/server.name/resourceid" +
|
47 | "?width=32&height=64&method=crop",
|
48 | );
|
49 | });
|
50 |
|
51 | it("should put fragments from mxc:// URIs after any query parameters",
|
52 | function() {
|
53 | const mxcUri = "mxc://server.name/resourceid#automade";
|
54 | expect(ContentRepo.getHttpUriForMxc(baseUrl, mxcUri, 32)).toEqual(
|
55 | baseUrl + "/_matrix/media/r0/thumbnail/server.name/resourceid" +
|
56 | "?width=32#automade",
|
57 | );
|
58 | });
|
59 |
|
60 | it("should put fragments from mxc:// URIs at the end of the HTTP URI",
|
61 | function() {
|
62 | const mxcUri = "mxc://server.name/resourceid#automade";
|
63 | expect(ContentRepo.getHttpUriForMxc(baseUrl, mxcUri)).toEqual(
|
64 | baseUrl + "/_matrix/media/r0/download/server.name/resourceid#automade",
|
65 | );
|
66 | });
|
67 | });
|
68 |
|
69 | describe("getIdenticonUri", function() {
|
70 | it("should do nothing for null input", function() {
|
71 | expect(ContentRepo.getIdenticonUri(null)).toEqual(null);
|
72 | });
|
73 |
|
74 | it("should set w/h by default to 96", function() {
|
75 | expect(ContentRepo.getIdenticonUri(baseUrl, "foobar")).toEqual(
|
76 | baseUrl + "/_matrix/media/unstable/identicon/foobar" +
|
77 | "?width=96&height=96",
|
78 | );
|
79 | });
|
80 |
|
81 | it("should be able to set custom w/h", function() {
|
82 | expect(ContentRepo.getIdenticonUri(baseUrl, "foobar", 32, 64)).toEqual(
|
83 | baseUrl + "/_matrix/media/unstable/identicon/foobar" +
|
84 | "?width=32&height=64",
|
85 | );
|
86 | });
|
87 |
|
88 | it("should URL encode the identicon string", function() {
|
89 | expect(ContentRepo.getIdenticonUri(baseUrl, "foo#bar", 32, 64)).toEqual(
|
90 | baseUrl + "/_matrix/media/unstable/identicon/foo%23bar" +
|
91 | "?width=32&height=64",
|
92 | );
|
93 | });
|
94 | });
|
95 | });
|