1 | "use strict";
|
2 |
|
3 |
|
4 |
|
5 |
|
6 |
|
7 |
|
8 |
|
9 |
|
10 |
|
11 |
|
12 |
|
13 |
|
14 |
|
15 |
|
16 |
|
17 | Object.defineProperty(exports, "__esModule", { value: true });
|
18 | const chai = require("chai");
|
19 | const endpoint_1 = require("./endpoint");
|
20 | const expect = chai.expect;
|
21 | describe('Endpoint', () => {
|
22 | describe('01 #getWebSocketUrl', () => {
|
23 | it('Should correctly join root pathname', () => {
|
24 | expectWsUri({
|
25 | httpScheme: 'ws',
|
26 | path: '/miau/'
|
27 | }, {
|
28 | host: 'example.org',
|
29 | pathname: '/',
|
30 | search: '',
|
31 | protocol: ''
|
32 | }, 'ws://example.org/miau/');
|
33 | });
|
34 | it('Should correctly join pathname and path', () => {
|
35 | expectWsUri({
|
36 | httpScheme: 'ws',
|
37 | path: '/miau/'
|
38 | }, {
|
39 | host: 'example.org',
|
40 | pathname: '/mainresource',
|
41 | search: '',
|
42 | protocol: ''
|
43 | }, 'ws://example.org/mainresource/miau/');
|
44 | });
|
45 | it('Should correctly join pathname and path, ignoring double slash in between', () => {
|
46 | expectWsUri({
|
47 | httpScheme: 'ws',
|
48 | path: '/miau/'
|
49 | }, {
|
50 | host: 'example.org',
|
51 | pathname: '/mainresource/',
|
52 | search: '',
|
53 | protocol: ''
|
54 | }, 'ws://example.org/mainresource/miau/');
|
55 | });
|
56 | it('Should correctly join pathname and path, without trailing slash', () => {
|
57 | expectWsUri({
|
58 | httpScheme: 'ws',
|
59 | path: '/miau'
|
60 | }, {
|
61 | host: 'example.org',
|
62 | pathname: '/mainresource',
|
63 | search: '',
|
64 | protocol: ''
|
65 | }, 'ws://example.org/mainresource/miau');
|
66 | });
|
67 | });
|
68 | describe('02 #httpScheme', () => {
|
69 | it('Should choose https:// if location protocol is https://', () => {
|
70 | expectRestUri({
|
71 | path: '/'
|
72 | }, {
|
73 | host: 'example.org',
|
74 | pathname: '/',
|
75 | search: '',
|
76 | protocol: 'https:'
|
77 | }, 'https://example.org/');
|
78 | });
|
79 | it("should return with the 'options.httpScheme' if defined", () => {
|
80 | expect(new endpoint_1.Endpoint({ httpScheme: 'foo:' }, {
|
81 | host: 'example.org',
|
82 | pathname: '/',
|
83 | search: '',
|
84 | protocol: 'https:'
|
85 | }).httpScheme).to.be.equal('foo:');
|
86 | });
|
87 | it('should return with the HTTP if the protocol is HTTP.', () => {
|
88 | expect(new endpoint_1.Endpoint({}, {
|
89 | host: 'example.org',
|
90 | pathname: '/',
|
91 | search: '',
|
92 | protocol: 'http:'
|
93 | }).httpScheme).to.be.equal('http:');
|
94 | });
|
95 | it('should return with the HTTPS if the protocol is HTTPS.', () => {
|
96 | expect(new endpoint_1.Endpoint({}, {
|
97 | host: 'example.org',
|
98 | pathname: '/',
|
99 | search: '',
|
100 | protocol: 'https:'
|
101 | }).httpScheme).to.be.equal('https:');
|
102 | });
|
103 | it('should return with the HTTP if the protocol is *not* HTTP or HTTPS.', () => {
|
104 | expect(new endpoint_1.Endpoint({}, {
|
105 | host: 'example.org',
|
106 | pathname: '/',
|
107 | search: '',
|
108 | protocol: 'file:'
|
109 | }).httpScheme).to.be.equal('http:');
|
110 | });
|
111 | });
|
112 | });
|
113 | function expectWsUri(options, mockLocation, expectedUri) {
|
114 | const cut = new endpoint_1.Endpoint(options, mockLocation);
|
115 | const uri = cut.getWebSocketUrl();
|
116 | expect(uri.toString()).to.eq(expectedUri);
|
117 | }
|
118 | function expectRestUri(options, mockLocation, expectedUri) {
|
119 | const cut = new endpoint_1.Endpoint(options, mockLocation);
|
120 | const uri = cut.getRestUrl();
|
121 | expect(uri.toString()).to.eq(expectedUri);
|
122 | }
|
123 |
|
\ | No newline at end of file |