UNPKG

4.75 kBJavaScriptView Raw
1"use strict";
2// *****************************************************************************
3// Copyright (C) 2017 TypeFox and others.
4//
5// This program and the accompanying materials are made available under the
6// terms of the Eclipse Public License v. 2.0 which is available at
7// http://www.eclipse.org/legal/epl-2.0.
8//
9// This Source Code may also be made available under the following Secondary
10// Licenses when the conditions for such availability set forth in the Eclipse
11// Public License v. 2.0 are satisfied: GNU General Public License, version 2
12// with the GNU Classpath Exception which is available at
13// https://www.gnu.org/software/classpath/license.html.
14//
15// SPDX-License-Identifier: EPL-2.0 OR GPL-2.0-only WITH Classpath-exception-2.0
16// *****************************************************************************
17Object.defineProperty(exports, "__esModule", { value: true });
18const chai = require("chai");
19const endpoint_1 = require("./endpoint");
20const expect = chai.expect;
21describe('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});
113function 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}
118function 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//# sourceMappingURL=endpoint.spec.js.map
\No newline at end of file