Permalink
Browse files

actually test lib/stars.js

...and assert that the required callback is there.
  • Loading branch information...
1 parent 1011c09 commit 283fc4f3795675265c5c230911679afc1981403a @othiym23 othiym23 committed May 22, 2014
Showing with 38 additions and 2 deletions.
  1. +2 −0 lib/request.js
  2. +4 −2 lib/stars.js
  3. +32 −0 test/stars.js
View
@@ -22,6 +22,8 @@ function toRegistryURL(registry, path) {
// 3. content-type is 'application/json' -- metadata
function regRequest (method, uri, options, cb_) {
assert(uri, "must pass resource to load")
+ assert(cb_, "must pass callback")
+
options = options || {}
var nofollow = !options.follow
var etag = options.etag
View
@@ -1,7 +1,9 @@
+var url = require("url")
+
module.exports = stars
-function stars (name, cb) {
+function stars (base, name, cb) {
name = encodeURIComponent(name)
var path = "/-/_view/starredByUser?key=\""+name+"\""
- this.request("GET", this.conf.get("registry"), path, cb)
+ this.request("GET", url.resolve(base, path), null, cb)
}
View
@@ -0,0 +1,32 @@
+var tap = require("tap")
+
+var server = require("./lib/server.js")
+var common = require("./lib/common.js")
+var client = common.freshClient({
+ username : "username",
+ password : "password",
+ email : "ogd@aoaioxxysz.net",
+ _auth : new Buffer("username : password").toString("base64"),
+ "always-auth" : true
+})
+
+var users = [
+ "benjamincoe",
+ "seldo",
+ "ceejbot"
+]
+
+tap.test("get the URL for the bugs page on a package", function (t) {
+ server.expect("GET", "/-/_view/starredByUser?key=%22sample%22", function (req, res) {
+ t.equal(req.method, "GET")
+
+ res.json(users)
+ })
+
+ client.stars("http://localhost:1337/", "sample", function (error, info) {
+ t.notOk(error, "no errors")
+ t.deepEqual(info, users, "got the list of users")
+
+ t.end()
+ })
+})

0 comments on commit 283fc4f

Please sign in to comment.