-
Notifications
You must be signed in to change notification settings - Fork 0
/
game_tests.js
93 lines (78 loc) · 3.1 KB
/
game_tests.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
define(function (require) {
'use strict';
var _ = require('/external/lodash/dist/lodash.js');
var api = require('/tests/support/api.js');
var should = require('/tests/support/should.js');
describe('game', function () {
beforeEach(api.logOutAndContinue);
describe('logged POST /api/games', function () {
beforeEach(function (done) {
var context = this;
context.username = 'Batima';
api.logIn(context)
.then(api.createGame)
.then(function (data, textStatus, jqXHR) {
context.gameHref = jqXHR.getResponseHeader('Location');
}).always(done.bind(null, null));
});
it('redirects to a created game', function (done) {
var context = this;
assert.notEqual(context.gameHref, null, 'Location != null');
api.get(context.gameHref).done(function (data, textStatus, jqXHR) {
assert.deepEqual(data._links.self, { href: context.gameHref });
}).always(done.bind(null, null));
});
it('starts with logged user in embedded players', function (done) {
var context = this;
api.get(context.gameHref).done(function (data, textStatus, jqXHR) {
should.be(data._embedded, should.bePlainObject, 'data._embedded');
assert.isArray(data._embedded.player, 'data._embedded.player');
assert.deepEqual(
_.pluck(data._embedded.player, 'displayName'),
[ context.username ],
'data._embedded.player#displayName'
);
}).always(done.bind(null, null));
});
});
describe('GET /api/game/:id', function () {
beforeEach(function (done) {
var context = this;
context.request = api.createTestGame(context).always(done.bind(null, null));
});
it('has link to self', function () {
assert.deepEqual(this.game._links.self, { href: this.gameHref });
});
it('content type is duelo-game', function () {
this.request.done(function (data, textStatus, jqXHR) {
var expectedType = 'duelo-game';
var type = jqXHR.getResponseHeader('Content-Type');
assert.equal(type, 'application/' + expectedType + '+json; charset=utf-8', 'Content-Type');
assert.equal(data._contentType, expectedType, 'data._contentType');
});
});
it('does not expose any _id\'s', function () {
assert.strictEqual(this.game._id, undefined, 'game._id');
assert.strictEqual(this.game._embedded.player[0]._id, undefined, 'game._embedded.player[0]._id');
});
});
describe('logged GET pre-existing /api/game/:id', function () {
beforeEach(function (done) {
var context = this;
context.username = 'O Palhaco';
api.createTestGame(context).then(
_.partial(api.logIn, context)
).then(
_.partial(api.getGame, context)
).then(done.bind(null, null));
});
it('has a link to the logged user', function () {
assert.deepEqual(
this.game._links['viewed-by'],
this.user._links.self,
'link[rel=viewed-by]'
);
});
});
});
});