mirror of
https://github.com/samsonjs/gitter.git
synced 2026-03-25 09:25:45 +00:00
add vows
This commit is contained in:
parent
58de0b9836
commit
ee8eb83f78
9 changed files with 382 additions and 0 deletions
7
Makefile
Normal file
7
Makefile
Normal file
|
|
@ -0,0 +1,7 @@
|
|||
VOWS=vows/{blob,branch,commit,raw,repo,tree,user}.js
|
||||
|
||||
spec:
|
||||
vows --spec $(VOWS)
|
||||
|
||||
test:
|
||||
vows $(VOWS)
|
||||
35
vows/blob.js
Normal file
35
vows/blob.js
Normal file
|
|
@ -0,0 +1,35 @@
|
|||
var gh = require('../lib')
|
||||
, vows = require('vows')
|
||||
, assert = require('assert')
|
||||
, h = require('./helper')
|
||||
|
||||
, User = 'samsonjs'
|
||||
, Repo = 'gitter'
|
||||
, Proj = User + '/' + Repo
|
||||
, TreeSha = '3363be22e88e50d6dd15f9a4b904bfe41cdd22bc'
|
||||
, Path = 'lib/index.js'
|
||||
|
||||
vows.describe('Blob').addBatch({
|
||||
'after fetching a blob': {
|
||||
topic: function() { gh.blob(Proj, TreeSha, Path, this.callback) },
|
||||
'the data object can be accessed with the data() method': function(err, blob) {
|
||||
assert.ifError(err)
|
||||
assert.ok(blob)
|
||||
assert.instanceOf(blob.data(), Object)
|
||||
},
|
||||
'data is a blob': function(err, blob) {
|
||||
assert.ifError(err)
|
||||
assert.ok(h.looksLikeABlob(blob.data()))
|
||||
},
|
||||
},
|
||||
'after fetching commits for a blob': {
|
||||
topic: function() { gh.blob(Proj, TreeSha, Path).getCommits(this.callback) },
|
||||
'list of commits is available': function(err, commits) {
|
||||
assert.ifError(err)
|
||||
assert.ok(commits)
|
||||
assert.instanceOf(commits, Array)
|
||||
assert.equal(commits.length, 1)
|
||||
assert.ok(commits.every(function(c) { return h.looksLikeACommit(c) }))
|
||||
}
|
||||
},
|
||||
}).export(module)
|
||||
37
vows/branch.js
Normal file
37
vows/branch.js
Normal file
|
|
@ -0,0 +1,37 @@
|
|||
var gh = require('../lib')
|
||||
, vows = require('vows')
|
||||
, assert = require('assert')
|
||||
, h = require('./helper')
|
||||
|
||||
, User = 'samsonjs'
|
||||
, Repo = 'gitter'
|
||||
, Proj = User + '/' + Repo
|
||||
, Branch = 'master'
|
||||
|
||||
vows.describe('Branch').addBatch({
|
||||
'after fetching a branch': {
|
||||
topic: function() { gh.branch(Proj, Branch, this.callback) },
|
||||
'the data object can be accessed with the data() method': function(err, branch) {
|
||||
assert.ifError(err)
|
||||
assert.ok(branch)
|
||||
assert.instanceOf(branch.data(), Object)
|
||||
},
|
||||
'attributes can be accessed with the data() method': function(err, branch) {
|
||||
assert.ifError(err)
|
||||
assert.instanceOf(branch.data('author'), Object)
|
||||
},
|
||||
'expected fields are present': function(err, branch) {
|
||||
assert.ifError(err)
|
||||
assert.ok(h.looksLikeABranch(branch.data()))
|
||||
},
|
||||
},
|
||||
'after fetching commits': {
|
||||
topic: function() { gh.commits(Proj, Branch, this.callback) },
|
||||
'list of commits is available': function(err, commits) {
|
||||
assert.ifError(err)
|
||||
assert.ok(commits)
|
||||
assert.instanceOf(commits, Array)
|
||||
assert.ok(commits.every(function(c) { return h.looksLikeACommit(c) }))
|
||||
}
|
||||
}
|
||||
}).export(module)
|
||||
28
vows/commit.js
Normal file
28
vows/commit.js
Normal file
|
|
@ -0,0 +1,28 @@
|
|||
var gh = require('../lib')
|
||||
, vows = require('vows')
|
||||
, assert = require('assert')
|
||||
, h = require('./helper')
|
||||
|
||||
, User = 'samsonjs'
|
||||
, Repo = 'gitter'
|
||||
, Proj = User + '/' + Repo
|
||||
, Sha = '3363be22e88e50d6dd15f9a4b904bfe41cdd22bc'
|
||||
|
||||
vows.describe('Commit').addBatch({
|
||||
'after fetching a commit': {
|
||||
topic: function() { gh.commit(Proj, Sha, this.callback) },
|
||||
'the data object can be accessed with the data() method': function(err, commit) {
|
||||
assert.ifError(err)
|
||||
assert.ok(commit)
|
||||
assert.instanceOf(commit.data(), Object)
|
||||
},
|
||||
'attributes can be accessed with the data() method': function(err, commit) {
|
||||
assert.ifError(err)
|
||||
assert.instanceOf(commit.data('author'), Object)
|
||||
},
|
||||
'expected fields are present': function(err, commit) {
|
||||
assert.ifError(err)
|
||||
assert.ok(h.looksLikeACommit(commit.data()))
|
||||
},
|
||||
}
|
||||
}).export(module)
|
||||
39
vows/helper.js
Normal file
39
vows/helper.js
Normal file
|
|
@ -0,0 +1,39 @@
|
|||
module.exports = { looksLikeABlob: looksLikeABlob
|
||||
, looksLikeABranch: looksLikeACommit
|
||||
, looksLikeACommit: looksLikeACommit
|
||||
, looksLikeAContributor: looksLikeAContributor
|
||||
, looksLikeARepo: looksLikeARepo
|
||||
, looksLikeASha: looksLikeASha
|
||||
, looksLikeATree: looksLikeATree
|
||||
, looksLikeAUser: looksLikeAUser
|
||||
}
|
||||
|
||||
var BlobKeys = ('mimeType mode name sha size').split(' ')
|
||||
|
||||
var CommitKeys = ('author authoredDate committedDate committer id ' +
|
||||
'message parents tree url').split(' ')
|
||||
|
||||
var ContributorKeys = ('blog contributions email location login name type').split(' ')
|
||||
|
||||
var RepoKeys = ('createdAt fork forks hasDownloads hasIssues hasWiki ' +
|
||||
'name openIssues owner private pushedAt url watchers').split(' ')
|
||||
|
||||
var UserKeys = ('blog company createdAt email followersCount ' +
|
||||
'followingCount id location login name ' +
|
||||
'publicRepoCount publicGistCount type').split(' ')
|
||||
|
||||
function looksLikeABlob(obj) { return hasKeys(obj, BlobKeys) }
|
||||
function looksLikeACommit(obj) { return hasKeys(obj, CommitKeys) }
|
||||
function looksLikeAContributor(obj) { return hasKeys(obj, ContributorKeys) }
|
||||
function looksLikeARepo(obj) { return hasKeys(obj, RepoKeys) }
|
||||
function looksLikeASha(s) { return s && s.length === 40 }
|
||||
function looksLikeATree(obj) { return obj && obj.every(function(b) { return looksLikeABlob(b) }) }
|
||||
function looksLikeAUser(obj) { return hasKeys(obj, UserKeys) }
|
||||
|
||||
function hasKeys(obj, keys) {
|
||||
return (obj && typeof obj === 'object' && keys.every(function(k) {
|
||||
if (!(k in obj))
|
||||
console.error( k + ' is not in ' + JSON.stringify(obj, null, 2))
|
||||
return k in obj
|
||||
}))
|
||||
}
|
||||
20
vows/raw.js
Normal file
20
vows/raw.js
Normal file
|
|
@ -0,0 +1,20 @@
|
|||
var gh = require('../lib')
|
||||
, vows = require('vows')
|
||||
, assert = require('assert')
|
||||
, h = require('./helper')
|
||||
|
||||
, User = 'samsonjs'
|
||||
, Repo = 'gitter'
|
||||
, Proj = User + '/' + Repo
|
||||
, Sha = 'a0a2d307cfe7810ccae0aec2ec6854d079de6511'
|
||||
|
||||
vows.describe('Raw').addBatch({
|
||||
'after fetching a raw blob': {
|
||||
topic: function() { gh.raw(Proj, Sha, this.callback) },
|
||||
'the data object can be accessed with the data() method': function(err, raw) {
|
||||
assert.ifError(err)
|
||||
assert.ok(raw)
|
||||
assert.equal(typeof raw.data(), 'string')
|
||||
}
|
||||
}
|
||||
}).export(module)
|
||||
100
vows/repo.js
Normal file
100
vows/repo.js
Normal file
|
|
@ -0,0 +1,100 @@
|
|||
var gh = require('../lib')
|
||||
, vows = require('vows')
|
||||
, assert = require('assert')
|
||||
, h = require('./helper')
|
||||
|
||||
, User = 'samsonjs'
|
||||
, Repo = 'gitter'
|
||||
, Proj = User + '/' + Repo
|
||||
|
||||
vows.describe('Repo').addBatch({
|
||||
'after fetching a repo': {
|
||||
topic: function() { gh.repo(Proj, this.callback) },
|
||||
'the data object can be accessed with the data() method': function(err, repo) {
|
||||
assert.ifError(err)
|
||||
assert.ok(repo)
|
||||
assert.instanceOf(repo.data(), Object)
|
||||
},
|
||||
'attributes can be accessed with the data() method': function(err, repo) {
|
||||
assert.ifError(err)
|
||||
assert.equal(repo.data('owner'), User)
|
||||
},
|
||||
'expected fields are present': function(err, repo) {
|
||||
assert.ifError(err)
|
||||
assert.ok(h.looksLikeARepo(repo.data()))
|
||||
},
|
||||
},
|
||||
'after fetching branches': {
|
||||
topic: function() { gh.branches(Proj, this.callback) },
|
||||
'map of branches is available': function(err, branches) {
|
||||
assert.ifError(err)
|
||||
assert.ok(branches)
|
||||
assert.instanceOf(branches, Object)
|
||||
assert.ok('master' in branches)
|
||||
},
|
||||
'names and commit ids of branches are available': function(err, branches) {
|
||||
assert.ifError(err)
|
||||
assert.ok(Object.keys(branches).every(function(b) { return h.looksLikeASha(branches[b]) }))
|
||||
}
|
||||
},
|
||||
'after fetching collaborators': {
|
||||
topic: function() { gh.collaborators(Proj, this.callback) },
|
||||
'list of collaborators is available': function(err, collaborators) {
|
||||
assert.ifError(err)
|
||||
assert.ok(collaborators && collaborators.length >= 1)
|
||||
assert.ok(collaborators.indexOf(User) !== -1)
|
||||
},
|
||||
'names of collaborators are available': function(err, collaborators) {
|
||||
assert.ifError(err)
|
||||
assert.ok(collaborators.every(function(c) { return c && c.length >= 1 }))
|
||||
}
|
||||
},
|
||||
'after fetching contributors': {
|
||||
topic: function() { gh.contributors(Proj, this.callback) },
|
||||
'list of contributors is available': function(err, contributors) {
|
||||
assert.ifError(err)
|
||||
assert.ok(contributors && contributors.length >= 1)
|
||||
},
|
||||
'names of contributors are available': function(err, contributors) {
|
||||
assert.ifError(err)
|
||||
assert.ok(contributors.every(function(c) { return h.looksLikeAContributor(c) }))
|
||||
}
|
||||
},
|
||||
'after fetching languages': {
|
||||
topic: function() { gh.languages(Proj, this.callback) },
|
||||
'map of languages is available': function(err, languages) {
|
||||
assert.ifError(err)
|
||||
assert.ok(languages)
|
||||
assert.instanceOf(languages, Object)
|
||||
assert.ok('JavaScript' in languages)
|
||||
}
|
||||
},
|
||||
'after fetching network': {
|
||||
topic: function() { gh.network(Proj, this.callback) },
|
||||
'map of network is available': function(err, network) {
|
||||
assert.ifError(err)
|
||||
assert.ok(network && network.length >= 1)
|
||||
assert.ok(network.every(function(r) { return h.looksLikeARepo(r) }))
|
||||
}
|
||||
},
|
||||
'after fetching tags': {
|
||||
topic: function() { gh.tags(Proj, this.callback) },
|
||||
'map of tags is available': function(err, tags) {
|
||||
assert.ifError(err)
|
||||
assert.ok(tags)
|
||||
assert.instanceOf(tags, Object)
|
||||
}
|
||||
},
|
||||
'after fetching watchers': {
|
||||
topic: function() { gh.watchers(Proj, this.callback) },
|
||||
'list of watchers is available': function(err, watchers) {
|
||||
assert.ifError(err)
|
||||
assert.ok(watchers && watchers.length >= 1)
|
||||
assert.ok(watchers.indexOf(User) !== -1)
|
||||
},
|
||||
'names of watchers are available': function(err, watchers) {
|
||||
assert.ifError(err)
|
||||
assert.ok(watchers.every(function(w) { return w && w.length >= 1 }))
|
||||
}
|
||||
}
|
||||
}).export(module)
|
||||
53
vows/tree.js
Normal file
53
vows/tree.js
Normal file
|
|
@ -0,0 +1,53 @@
|
|||
var gh = require('../lib')
|
||||
, vows = require('vows')
|
||||
, assert = require('assert')
|
||||
, h = require('./helper')
|
||||
|
||||
, User = 'samsonjs'
|
||||
, Repo = 'gitter'
|
||||
, Proj = User + '/' + Repo
|
||||
, TreeSha = '3363be22e88e50d6dd15f9a4b904bfe41cdd22bc'
|
||||
|
||||
vows.describe('Tree').addBatch({
|
||||
'after fetching a tree': {
|
||||
topic: function() { gh.tree(Proj, TreeSha, this.callback) },
|
||||
'the data object can be accessed with the data() method': function(err, tree) {
|
||||
assert.ifError(err)
|
||||
assert.ok(tree)
|
||||
assert.instanceOf(tree.data(), Array)
|
||||
},
|
||||
'data is a git tree': function(err, tree) {
|
||||
assert.ifError(err)
|
||||
assert.ok(h.looksLikeATree(tree.blobs))
|
||||
},
|
||||
},
|
||||
'after fetching blobs': {
|
||||
topic: function() { gh.blobs(Proj, TreeSha, this.callback) },
|
||||
'list of blobs is available': function(err, blobs) {
|
||||
assert.ifError(err)
|
||||
assert.ok(blobs)
|
||||
assert.instanceOf(blobs, Object)
|
||||
assert.ok(Object.keys(blobs).length > 1)
|
||||
assert.ok('package.json' in blobs)
|
||||
assert.ok(Object.keys(blobs).every(function(k) { return h.looksLikeASha(blobs[k]) }))
|
||||
}
|
||||
},
|
||||
'after fetching full blobs': {
|
||||
topic: function() { gh.tree(Proj, TreeSha).getFullBlobs(this.callback) },
|
||||
'full blobs are available': function(err, blobs) {
|
||||
assert.ifError(err)
|
||||
assert.ok(blobs)
|
||||
assert.instanceOf(blobs, Array)
|
||||
assert.ok(blobs.every(function(b) { return h.looksLikeABlob(b) }))
|
||||
}
|
||||
},
|
||||
'after fetching the full tree': {
|
||||
topic: function() { gh.tree(Proj, TreeSha).getFullTree(this.callback) },
|
||||
'full contents of tree are available': function(err, tree) {
|
||||
assert.ifError(err)
|
||||
assert.ok(tree)
|
||||
assert.instanceOf(tree, Array)
|
||||
assert.ok(tree.every(function(b) { return h.looksLikeABlob(b) }))
|
||||
}
|
||||
}
|
||||
}).export(module)
|
||||
63
vows/user.js
Normal file
63
vows/user.js
Normal file
|
|
@ -0,0 +1,63 @@
|
|||
var gh = require('../lib')
|
||||
, vows = require('vows')
|
||||
, assert = require('assert')
|
||||
, h = require('./helper')
|
||||
|
||||
, User = 'samsonjs'
|
||||
|
||||
vows.describe('User').addBatch({
|
||||
'after fetching a user': {
|
||||
topic: function() { gh.user(User, this.callback) },
|
||||
'the data object can be accessed with the data() method': function(err, user) {
|
||||
assert.ifError(err)
|
||||
assert.ok(user)
|
||||
assert.instanceOf(user.data(), Object)
|
||||
},
|
||||
'attributes can be accessed with the data() method': function(err, user) {
|
||||
assert.ifError(err)
|
||||
assert.equal(user.data('login'), User)
|
||||
},
|
||||
'expected fields are present': function(err, user) {
|
||||
assert.ifError(err)
|
||||
assert.ok(h.looksLikeAUser(user.data()))
|
||||
},
|
||||
},
|
||||
'after fetching their followers': {
|
||||
topic: function() { gh.followers(User, this.callback) },
|
||||
'list of followers is available': function(err, followers) {
|
||||
assert.ifError(err)
|
||||
assert.ok(followers && followers.length > 1)
|
||||
},
|
||||
'usernames of followers are available': function(err, followers) {
|
||||
assert.ifError(err)
|
||||
assert.ok(followers.every(function(f) { return f && f.length > 1 }))
|
||||
}
|
||||
},
|
||||
'after fetching users they follow': {
|
||||
topic: function() { gh.following(User, this.callback) },
|
||||
'list of following users is available': function(err, following) {
|
||||
assert.ifError(err)
|
||||
assert.ok(following && following.length > 1)
|
||||
},
|
||||
'names of following users are available': function(err, following) {
|
||||
assert.ifError(err)
|
||||
assert.ok(following.every(function(f) { return f && f.length > 1 }))
|
||||
}
|
||||
},
|
||||
'after fetching their public repos': {
|
||||
topic: function() { gh.repos(User, this.callback) },
|
||||
'list of public repos is available': function(err, repos) {
|
||||
assert.ifError(err)
|
||||
assert.ok(repos.length > 1)
|
||||
assert.ok(repos.every(function(r) { return h.looksLikeARepo(r) }))
|
||||
}
|
||||
},
|
||||
'after fetching their watched repos': {
|
||||
topic: function() { gh.watched(User, this.callback) },
|
||||
'list of watched repos is available': function(err, repos) {
|
||||
assert.ifError(err)
|
||||
assert.ok(repos.length > 1)
|
||||
assert.ok(repos.every(function(r) { return h.looksLikeARepo(r) }))
|
||||
}
|
||||
}
|
||||
}).export(module)
|
||||
Loading…
Reference in a new issue