Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
3 changed files
with
40 additions
and
28 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,28 +1,43 @@ | ||
/*global it:true, describe:true */ | ||
var Resource = require('src/resource'); | ||
var LinkCollection = require('src/links'); | ||
var Link = require('src/link'); | ||
var parser = require('src/parser'); | ||
|
||
describe("Resources", function () { | ||
"use strict"; | ||
it("should be a function", function () { | ||
Resource.should.be.a('function'); | ||
}); | ||
|
||
it("can not be instantiated without links", function () { | ||
var errorFn = function () { | ||
new Resource({}, null, {}); | ||
}; | ||
errorFn.should.throw(Error); | ||
it("MUST have a resource as its root object", function () { | ||
parser({}).should.be.instanceOf(Resource); | ||
parser.bind(undefined, []).should.throw(Error); | ||
parser.bind(undefined).should.throw(Error); | ||
parser.bind(undefined, "invalid").should.throw(Error); | ||
}); | ||
|
||
it("OPTIONALLY has a _embedded property", function () { | ||
var r1 = parser({}); | ||
r1.embedded().should.be.empty; | ||
|
||
var _withEmbedded = {_embedded: {emb: {}}}; | ||
var r2 = parser(_withEmbedded); | ||
r2.embedded().should.not.be.empty; | ||
}); | ||
|
||
it("can be instantiated only with _self link", function () { | ||
var errorFn = function () { | ||
new Resource({}, {}, null); | ||
}; | ||
errorFn.should.throw(Error); | ||
it("OPTIONALLY has a _links property", function () { | ||
var r1 = parser({}); | ||
r1.links().should.be.empty; | ||
|
||
var goodFn = function () { | ||
new Resource({}, {self: 'dummy'}); | ||
}; | ||
goodFn.should.not.throw(Error); | ||
var r2 = parser({_links: {self: '..'}}); | ||
r2.links().should.be.instanceOf(LinkCollection); | ||
}); | ||
|
||
it("should have Link instances as link properties", function () { | ||
var r2 = parser({_links: {self: '..'}}); | ||
r2.links('self').should.be.instanceOf(Link); | ||
}); | ||
|
||
}); | ||
|