This repository has been archived by the owner on Nov 7, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 39
/
Copy pathtest.permalinks.js
118 lines (111 loc) · 4.61 KB
/
test.permalinks.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
var server = require('../lib/unhangout-server'),
models = require("../lib/server-models"),
expect = require('expect.js'),
_ = require('underscore')._,
request = require('superagent'),
seed = require('../bin/seed.js'),
common = require("./common");
describe('PERMALINKS', function(){
beforeEach(function(done) {
common.standardSetup(function() {
var pms = new models.ServerSession({
isPermalinkSession: true,
shortCode: "test"
});
common.server.db.permalinkSessions.add(pms);
done();
});
});
afterEach(common.standardShutdown);
it("should require authentication for permalinks", function(done) {
request.get(common.URL + '/h/')
.redirects(0)
.end(function(res){
expect(res.status).to.be(302);
expect(res.headers.location).to.be("/auth/google");
done();
});
});
it("should require authentication for permalink details", function(done) {
request.get(common.URL + '/h/test')
.redirects(0)
.end(function(res){
expect(res.status).to.be(302);
expect(res.headers.location).to.be("/auth/google");
done();
});
});
it('should direct to the landing page when there is no code', function(done){
request.get(common.URL + '/h/')
.set("x-mock-user", "regular1")
.end(function(res){
expect(res.status).to.be(200);
done();
});
});
it('if :code is new, it should create a new session on the server', function(done){
request.get(common.URL + '/h/new-test')
.set("x-mock-user", "regular1")
.redirects(0)
.end(function(res){
expect(res.status).to.be(302);
expect(res.headers.location.indexOf("/h/admin/new-test")).to.be(0);
expect(common.server.db.permalinkSessions.findWhere({
shortCode: "new-test"
})).to.not.eql(undefined);
done();
});
});
it('if :code is active, multiple requests only create one session', function(done){
request.get(common.URL + '/h/test2')
.set("x-mock-user", "regular1")
.redirects(0)
.end(function(res){
expect(res.status).to.be(302);
expect(res.headers.location.indexOf("/h/admin/test2")).to.be(0);
var length = common.server.db.permalinkSessions.length;
request.get(common.URL + '/h/test2')
.set("x-mock-user", "regular1")
.end(function(res){
expect(res.status).to.be(200);
expect(common.server.db.permalinkSessions.length).to.be(length);
done();
});
});
});
it('if :code is new, it should present the form only for first visitor', function(done){
request.get(common.URL + '/h/test2')
.set("x-mock-user", "regular1")
.end(function(res){
expect(res.text.indexOf('<input')).to.not.eql(-1);
request.get(common.URL + '/h/test2')
.set("x-mock-user", "regular1")
.end(function(res){
expect(res.text.indexOf('<input')).to.be(-1);
done();
});
});
});
it('should reject requests without a valid creation key in the request body', function(done){
var session = common.server.db.permalinkSessions[0];
request.post(common.URL + '/h/admin/test')
.set("x-mock-user", "regular1")
.send({creationKey: 'wrong1', title: 'migrate title', description: 'something cool'})
.end(function(res){
expect(res.status).to.be(403);
done();
});
});
it('should update session title and description when valid creation key is present', function(done){
var session = common.server.db.permalinkSessions.at(0);
request.post(common.URL + '/h/admin/test')
.set("x-mock-user", "regular1")
.send({creationKey: session.get('creationKey'), title: 'migrate title', description: 'something cool'})
.end(function(res){
expect(res.status).to.be(200);
expect(session.get('title')).to.be('migrate title');
expect(session.get('description')).to.be('something cool');
done();
});
});
});