forked from alexbain/lirc_web
-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathlirc_web.js
More file actions
83 lines (69 loc) · 2.59 KB
/
lirc_web.js
File metadata and controls
83 lines (69 loc) · 2.59 KB
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
var app = require('../app'),
assert = require('assert'),
request = require('supertest'),
sinon = require('sinon');
jsdom = require("jsdom");
describe('lirc_web', function() {
describe('routes', function() {
it('should have an index route "/"', function(done) {
assert(request(app).get('/').expect(200, done));
});
it('should have a POST route for sending a command', function(done) {
assert(request(app).post('/remotes/tv/power').expect(200, done));
});
it('should have a POST route to start repeatedly sending a command', function(done) {
assert(request(app).post('/remotes/tv/volumeup/send_start').expect(200, done));
});
it('should have a POST route to stop repeatedly sending a command', function(done) {
assert(request(app).post('/remotes/tv/volumeup/send_stop').expect(200, done));
});
});
describe('index action', function() {
it('should return an HTML document', function(done) {
assert(request(app).get('/').expect('Content-Type', /html/, done));
});
it('should return an HTML document in which all button elements of class command-link have an href of the form /remotes/:remote/:command', function(done) {
request(app)
.get('/')
.end(function(err, res) {
assert.equal(err, null);
jsdom.env(res.text, ["http://code.jquery.com/jquery.js"], function (errors, window) {
var $ = window.$;
$("button.command-link").each(function(idx, elem) {
var s = $(elem).attr('href').split("/");
assert.equal(4, s.length);
assert.equal("", s[0]);
assert.equal("remotes", s[1]);
});
done();
});
});
});
});
describe('json api', function() {
it('should return a list of all remotes (and commands) when /remotes.json is accessed', function(done) {
request(app)
.get('/remotes.json')
.end(function(err, res) {
assert.equal(res.status, 200);
done();
});
});
it('should return a list of all commands for a remote when /remotes/:remote.json is accessed', function(done) {
request(app)
.get('/remotes/Microsoft_Xbox360.json')
.end(function(err, res) {
assert.equal(res.status, 200);
done();
});
});
it('should return a 404 for an unknown remote', function(done) {
request(app)
.get('/remotes/DOES_NOT_EXIST.json')
.end(function(err, res) {
assert.equal(res.status, 404);
done();
});
});
});
});