1 | require('./common');
|
2 | var LastFmBase = require("../lib/lastfm/lastfm-base");
|
3 |
|
4 | (function() {
|
5 | describe("LastFmBase");
|
6 |
|
7 | it("is an event emitter", function() {
|
8 | var events = { expected: function(){} };
|
9 | var gently = new Gently();
|
10 | var lastfmBase = new LastFmBase();
|
11 | gently.expect(events, "expected");
|
12 | lastfmBase.on("test", function() {
|
13 | events.expected();
|
14 | });
|
15 | lastfmBase.emit("test");
|
16 | });
|
17 | })();
|
18 |
|
19 | (function() {
|
20 | describe("LastFmBase.registerHandlers");
|
21 |
|
22 | it("attaches events specified in handelers parameter", function() {
|
23 | var handlers = {
|
24 | error: function() { },
|
25 | success: function() { },
|
26 | anything: function() { }
|
27 | };
|
28 | var gently = new Gently();
|
29 | gently.expect(handlers, "error");
|
30 | gently.expect(handlers, "success");
|
31 | gently.expect(handlers, "anything");
|
32 | var lastfmBase = new LastFmBase();
|
33 | lastfmBase.registerHandlers(handlers);
|
34 | lastfmBase.emit("error");
|
35 | lastfmBase.emit("success");
|
36 | lastfmBase.emit("anything");
|
37 | });
|
38 | })();
|
39 |
|
40 | (function() {
|
41 | var lastfmBase, original;
|
42 |
|
43 | describe("LastFmBase.filterParameters");
|
44 |
|
45 | before(function() {
|
46 | lastfmBase = new LastFmBase();
|
47 | original = { one: 1, two: 2, three: 3 };
|
48 | });
|
49 |
|
50 | it("unfiltered object matches original object", function() {
|
51 | var copy = lastfmBase.filterParameters(original);
|
52 | assert.deepEqual(copy, original);
|
53 | });
|
54 |
|
55 | it("returns copy of original object", function() {
|
56 | var copy = lastfmBase.filterParameters(original);
|
57 | copy.four = 4;
|
58 | assert.notDeepEqual(copy, original);
|
59 | });
|
60 |
|
61 | it("filteres out blacklisted parameters", function() {
|
62 | var copy = lastfmBase.filterParameters(original, ["one", "three"]);
|
63 | assert.equal(typeof copy.one, "undefined");
|
64 | assert.equal(typeof copy.three, "undefined");
|
65 | assert.equal(copy.two, 2);
|
66 | });
|
67 |
|
68 | it("automatically removed error, success, handler parameters", function() {
|
69 | var copy = lastfmBase.filterParameters({
|
70 | error: emptyFn,
|
71 | success: emptyFn,
|
72 | handlers: { }
|
73 | });
|
74 | assert.equal(typeof copy.error, "undefined");
|
75 | assert.equal(typeof copy.success, "undefined");
|
76 | assert.equal(typeof copy.handlers, "undefined");
|
77 | });
|
78 | })();
|