|
1 |
| -'use strict' |
| 1 | +"use strict"; |
2 | 2 |
|
3 |
| -const request = require('supertest') |
4 |
| -const {expect} = require('chai') |
5 |
| -const sinon = require('sinon') |
6 |
| -const {allFilenames} = require('../utils') |
| 3 | +const request = require("supertest"); |
| 4 | +const { expect } = require("chai"); |
| 5 | +const sinon = require("sinon"); |
| 6 | +const { allFilenames } = require("../utils"); |
7 | 7 |
|
8 |
| -const app = require('../../server/index') |
| 8 | +const app = require("../../server/index"); |
9 | 9 |
|
10 | 10 | const userInfo = {
|
11 |
| - emails: [{value: '[email protected]'}], |
12 |
| - id: '10', |
13 |
| - userId: '10', |
14 |
| - _json: {domain: 'test.com'} |
15 |
| -} |
| 11 | + emails: [{ value: "[email protected]" }], |
| 12 | + id: "10", |
| 13 | + userId: "10", |
| 14 | + _json: { domain: "test.com" }, |
| 15 | +}; |
16 | 16 |
|
17 |
| -describe('Server responses', () => { |
18 |
| - beforeEach(() => sinon.stub(app.request, 'session').value({passport: {user: userInfo}})) |
19 |
| - afterEach(() => sinon.restore()) |
| 17 | +describe("Server responses", () => { |
| 18 | + beforeEach(() => |
| 19 | + sinon.stub(app.request, "session").value({ passport: { user: userInfo } }) |
| 20 | + ); |
| 21 | + afterEach(() => sinon.restore()); |
20 | 22 |
|
21 |
| - describe('that return HTML', () => { |
22 |
| - it('should return 200 and content for homepage', () => { |
| 23 | + describe("that return HTML", () => { |
| 24 | + it("should return 200 and content for homepage", () => { |
23 | 25 | return request(app)
|
24 |
| - .get('/') |
| 26 | + .get("/") |
25 | 27 | .expect(200)
|
26 |
| - .then((res) => expect(res.text).to.include('<title>Team Library</title>')) |
27 |
| - }) |
| 28 | + .then((res) => |
| 29 | + expect(res.text).to.include("<title>Team Library</title>") |
| 30 | + ); |
| 31 | + }); |
28 | 32 |
|
29 |
| - it('should return 200 OK for healthcheck', () => { |
| 33 | + it("should return 200 OK for healthcheck", () => { |
30 | 34 | return request(app)
|
31 |
| - .get('/healthcheck') |
| 35 | + .get("/healthcheck") |
32 | 36 | .expect(200)
|
33 | 37 | .then((res) => {
|
34 |
| - expect(res.text).to.equal('OK') |
35 |
| - }) |
36 |
| - }) |
| 38 | + expect(res.text).to.equal("OK"); |
| 39 | + }); |
| 40 | + }); |
37 | 41 |
|
38 |
| - it('should display subfolders for folder', () => { |
| 42 | + it("should display subfolders for folder", () => { |
39 | 43 | return request(app)
|
40 |
| - .get('/test-folder-1') |
| 44 | + .get("/test-folder-1") |
41 | 45 | .expect(200)
|
42 | 46 | .then((res) => {
|
43 | 47 | // check it resolves name correclty
|
44 |
| - expect(res.text).to.include('Pages in Test Folder 1') |
| 48 | + expect(res.text).to.include("Pages in Test Folder 1"); |
45 | 49 | // check it has links to children
|
46 |
| - expect(res.text).to.include('Article 1 in test folder 1') |
47 |
| - expect(res.text).to.include('Article 2 in test folder 1') |
48 |
| - }) |
49 |
| - }) |
| 50 | + expect(res.text).to.include("Article 1 in test folder 1"); |
| 51 | + expect(res.text).to.include("Article 2 in test folder 1"); |
| 52 | + }); |
| 53 | + }); |
50 | 54 |
|
51 |
| - it('should remove trailing slash and redirect', () => { |
52 |
| - return request(app) |
53 |
| - // should strip trailing slash |
54 |
| - .get('/test-folder-1/') |
55 |
| - .expect(302) // Should be cached at this point |
56 |
| - .then((res) => { |
57 |
| - expect(res.text).to.equal('Found. Redirecting to /test-folder-1') |
58 |
| - }) |
59 |
| - }) |
| 55 | + it("should remove trailing slash and redirect", () => { |
| 56 | + return ( |
| 57 | + request(app) |
| 58 | + // should strip trailing slash |
| 59 | + .get("/test-folder-1/") |
| 60 | + .expect(302) // Should be cached at this point |
| 61 | + .then((res) => { |
| 62 | + expect(res.text).to.equal("Found. Redirecting to /test-folder-1"); |
| 63 | + }) |
| 64 | + ); |
| 65 | + }); |
60 | 66 |
|
61 |
| - it('should render top level folder in categories', () => { |
| 67 | + it("should render top level folder in categories", () => { |
62 | 68 | return request(app)
|
63 |
| - .get('/categories') |
| 69 | + .get("/categories") |
64 | 70 | .expect(200)
|
65 | 71 | .then((res) => {
|
66 |
| - expect(res.text).to.include('<h3>\n <a href="/test-folder-1">\n Test Folder 1\n </a>\n </h3>') |
67 |
| - }) |
68 |
| - }) |
| 72 | + expect(res.text).to.include( |
| 73 | + '<h3>\n <a href="/test-folder-1">\n Test Folder 1\n </a>\n </h3>' |
| 74 | + ); |
| 75 | + }); |
| 76 | + }); |
69 | 77 |
|
70 | 78 | // also tests insertion into datastore
|
71 |
| - it('folder with home doc should render the doc', () => { |
| 79 | + it("folder with home doc should render the doc", () => { |
72 | 80 | return request(app)
|
73 |
| - .get('/test-folder-9') |
| 81 | + .get("/test-folder-9") |
74 | 82 | .expect(200)
|
75 | 83 | .then((res) => {
|
76 |
| - expect(res.text).to.include('<h1 class="headline">Home article 10 for test folder 9</h1>') |
77 |
| - expect(res.text).to.include('By <span class="author">John Smith</span>') |
78 |
| - expect(res.text).to.include('Last edited by <span class="author">Foo Bar</span>') |
79 |
| - expect(res.text).to.include('Home article 10 for test folder 9') |
80 |
| - }) |
81 |
| - }) |
| 84 | + expect(res.text).to.include( |
| 85 | + '<h1 class="headline">Home article 10 for test folder 9</h1>' |
| 86 | + ); |
| 87 | + expect(res.text).to.include( |
| 88 | + 'By <span class="author">John Smith</span>' |
| 89 | + ); |
| 90 | + expect(res.text).to.include( |
| 91 | + 'Last edited by <span class="author">Foo Bar</span>' |
| 92 | + ); |
| 93 | + expect(res.text).to.include("Home article 10 for test folder 9"); |
| 94 | + }); |
| 95 | + }); |
82 | 96 |
|
83 |
| - it('duplicate doc should render a warning', () => { |
| 97 | + it("duplicate doc should render a warning", () => { |
84 | 98 | return request(app)
|
85 |
| - .get('/test-folder-9/article-3-in-test-folder-9') |
| 99 | + .get("/test-folder-9/article-3-in-test-folder-9") |
86 | 100 | .expect(200)
|
87 | 101 | .then((res) => {
|
88 |
| - expect(res.text).to.include('<h1 class="headline">Article 3 in test folder 9</h1>') |
89 |
| - expect(res.text).to.include('By <span class="author">John Smith</span>') |
90 |
| - expect(res.text).to.include('Last edited by <span class="author">Foo Bar</span>') |
91 |
| - expect(res.text).to.include('Article 3 in test folder 9') |
| 102 | + expect(res.text).to.include( |
| 103 | + '<h1 class="headline">Article 3 in test folder 9</h1>' |
| 104 | + ); |
| 105 | + expect(res.text).to.include( |
| 106 | + 'By <span class="author">John Smith</span>' |
| 107 | + ); |
| 108 | + expect(res.text).to.include( |
| 109 | + 'Last edited by <span class="author">Foo Bar</span>' |
| 110 | + ); |
| 111 | + expect(res.text).to.include("Article 3 in test folder 9"); |
92 | 112 | expect(res.text).to.include(
|
93 | 113 | '<div class="warning">\n Warning: Multiple resources in ' +
|
94 |
| - '<a href="https://drive.google.com/drive/u/0/folders/TestFolder9" target="_blank">' + |
95 |
| - 'this folder</a> share the same name: Article 3 in test folder 9. Only one will be ' + |
96 |
| - 'accesible through Library.\n</div>' |
97 |
| - ) |
98 |
| - }) |
99 |
| - }) |
| 114 | + '<a href="https://drive.google.com/drive/u/0/folders/TestFolder9" target="_blank">' + |
| 115 | + "this folder</a> share the same name: Article 3 in test folder 9. Only one will be " + |
| 116 | + "accesible through Library.\n</div>" |
| 117 | + ); |
| 118 | + }); |
| 119 | + }); |
100 | 120 |
|
101 |
| - it('should render an inline <style> tag and no JS on error pages', () => { |
| 121 | + it("should render an inline <style> tag and no JS on error pages", () => { |
102 | 122 | return request(app)
|
103 |
| - .get('/this-route-does-not-exist') |
| 123 | + .get("/this-route-does-not-exist") |
104 | 124 | .expect(404)
|
105 | 125 | .then((res) => {
|
106 |
| - expect(res.text).to.match(/<style type="text\/css">[^<]/i) |
107 |
| - expect(res.text).to.not.include('<link href="/assets') |
108 |
| - expect(res.text).to.not.include('<script src="/assets') |
109 |
| - }) |
110 |
| - }) |
111 |
| - }) |
| 126 | + expect(res.text).to.match(/<style type="text\/css">[^<]/i); |
| 127 | + expect(res.text).to.not.include('<link href="/assets'); |
| 128 | + expect(res.text).to.not.include('<script src="/assets'); |
| 129 | + }); |
| 130 | + }); |
| 131 | + }); |
112 | 132 |
|
113 |
| - describe('that return JSON', () => { |
114 |
| - it('should contain a complete filename listing', () => { |
| 133 | + describe("that return JSON", () => { |
| 134 | + it("should contain a complete filename listing", () => { |
115 | 135 | return request(app)
|
116 |
| - .get('/filename-listing.json') |
| 136 | + .get("/filename-listing.json") |
117 | 137 | .expect(200)
|
118 | 138 | .then((res) => {
|
119 |
| - const {filenames} = res.body |
120 |
| - expect(Array.isArray(filenames), 'cached file listing should be an array') |
121 |
| - expect(filenames).to.include(...allFilenames) |
122 |
| - expect(filenames.length).to.equal(allFilenames.length) |
123 |
| - }) |
124 |
| - }) |
| 139 | + const { filenames } = res.body; |
| 140 | + expect( |
| 141 | + Array.isArray(filenames), |
| 142 | + "cached file listing should be an array" |
| 143 | + ); |
| 144 | + expect(filenames).to.include(...allFilenames); |
| 145 | + expect(filenames.length).to.equal(allFilenames.length); |
| 146 | + }); |
| 147 | + }); |
125 | 148 |
|
126 |
| - it('folder with home doc should render the doc', () => { |
| 149 | + it("folder with home doc should render the doc", () => { |
127 | 150 | return request(app)
|
128 |
| - .get('/test-folder-9') |
129 |
| - .set('Accept', 'application/json') |
| 151 | + .get("/test-folder-9") |
| 152 | + .set("Accept", "application/json") |
130 | 153 | .expect(200)
|
131 |
| - .expect('Content-Type', /json/) |
| 154 | + .expect("Content-Type", /json/) |
132 | 155 | .then((res) => {
|
133 |
| - const data = JSON.parse(res.text) |
134 |
| - expect(data).to.deep.include( |
135 |
| - { |
136 |
| - url: '/test-folder-9', |
137 |
| - title: 'Home article 10 for test folder 9', |
138 |
| - lastUpdatedBy: 'Foo Bar', |
139 |
| - modifiedAt: '2018-03-02T14:13:20.000Z', |
140 |
| - createdAt: '2018-02-19T00:26:40.000Z', |
141 |
| - id: 'Test10', |
142 |
| - resourceType: 'document', |
143 |
| - content: '<p> This is a simple test document export.</p>', |
144 |
| - byline: 'John Smith', |
145 |
| - createdBy: 'John Smith', |
146 |
| - sections: [] |
147 |
| - } |
148 |
| - ) |
149 |
| - }) |
150 |
| - }) |
| 156 | + const data = JSON.parse(res.text); |
| 157 | + expect(data).to.deep.include({ |
| 158 | + url: "/test-folder-9", |
| 159 | + title: "Home article 10 for test folder 9", |
| 160 | + lastUpdatedBy: "Foo Bar", |
| 161 | + modifiedAt: "2018-03-02T14:13:20.000Z", |
| 162 | + createdAt: "2018-02-19T00:26:40.000Z", |
| 163 | + id: "Test10", |
| 164 | + resourceType: "document", |
| 165 | + content: "<p> This is a simple test document export.</p>", |
| 166 | + byline: "John Smith", |
| 167 | + createdBy: "John Smith", |
| 168 | + sections: [], |
| 169 | + }); |
| 170 | + }); |
| 171 | + }); |
151 | 172 |
|
152 |
| - it('folder with home doc should render the doc (.json suffix)', () => { |
| 173 | + it("folder with home doc should render the doc (.json suffix)", () => { |
153 | 174 | return request(app)
|
154 |
| - .get('/test-folder-9.json') |
| 175 | + .get("/test-folder-9.json") |
155 | 176 | .expect(200)
|
156 |
| - .expect('Content-Type', /json/) |
| 177 | + .expect("Content-Type", /json/) |
157 | 178 | .then((res) => {
|
158 |
| - const data = JSON.parse(res.text) |
159 |
| - expect(data).to.deep.include( |
160 |
| - { |
161 |
| - url: '/test-folder-9', |
162 |
| - title: 'Home article 10 for test folder 9', |
163 |
| - lastUpdatedBy: 'Foo Bar', |
164 |
| - modifiedAt: '2018-03-02T14:13:20.000Z', |
165 |
| - createdAt: '2018-02-19T00:26:40.000Z', |
166 |
| - id: 'Test10', |
167 |
| - resourceType: 'document', |
168 |
| - content: '<p> This is a simple test document export.</p>', |
169 |
| - byline: 'John Smith', |
170 |
| - createdBy: 'John Smith', |
171 |
| - sections: [] |
172 |
| - } |
173 |
| - ) |
174 |
| - }) |
175 |
| - }) |
176 |
| - }) |
177 |
| -}) |
| 179 | + const data = JSON.parse(res.text); |
| 180 | + expect(data).to.deep.include({ |
| 181 | + url: "/test-folder-9", |
| 182 | + title: "Home article 10 for test folder 9", |
| 183 | + lastUpdatedBy: "Foo Bar", |
| 184 | + modifiedAt: "2018-03-02T14:13:20.000Z", |
| 185 | + createdAt: "2018-02-19T00:26:40.000Z", |
| 186 | + id: "Test10", |
| 187 | + resourceType: "document", |
| 188 | + content: "<p> This is a simple test document export.</p>", |
| 189 | + byline: "John Smith", |
| 190 | + createdBy: "John Smith", |
| 191 | + sections: [], |
| 192 | + }); |
| 193 | + }); |
| 194 | + }); |
| 195 | + }); |
| 196 | +}); |
0 commit comments