2014-01-03 13:32:13 -05:00
|
|
|
require '../common'
|
|
|
|
|
|
|
|
describe '/db/<id>/version', ->
|
|
|
|
request = require 'request'
|
|
|
|
it 'clears the db first', (done) ->
|
|
|
|
clearModels [User, Article], (err) ->
|
|
|
|
throw err if err
|
|
|
|
done()
|
|
|
|
|
2014-06-30 22:16:26 -04:00
|
|
|
article = {name: 'Yo', body: 'yo ma'}
|
2014-01-03 13:32:13 -05:00
|
|
|
url = getURL('/db/article')
|
|
|
|
articles = {}
|
|
|
|
|
|
|
|
it 'sets up', (done) ->
|
|
|
|
loginAdmin ->
|
2014-06-30 22:16:26 -04:00
|
|
|
request.post {uri: url, json: article}, (err, res, body) ->
|
2014-01-03 13:32:13 -05:00
|
|
|
expect(res.statusCode).toBe(200)
|
|
|
|
articles[0] = body
|
|
|
|
new_article = _.clone(articles[0])
|
|
|
|
new_article.body = '...'
|
2014-06-30 22:16:26 -04:00
|
|
|
request.post {uri: url, json: new_article}, (err, res, body) ->
|
2014-01-03 13:32:13 -05:00
|
|
|
expect(res.statusCode).toBe(200)
|
|
|
|
articles[1] = body
|
|
|
|
new_article = _.clone(articles[1])
|
|
|
|
delete new_article.version
|
2014-06-30 22:16:26 -04:00
|
|
|
request.post {uri: url, json: new_article}, (err, res, body) ->
|
2014-01-03 13:32:13 -05:00
|
|
|
expect(res.statusCode).toBe(200)
|
|
|
|
articles[2] = body
|
|
|
|
done()
|
2014-06-30 22:16:26 -04:00
|
|
|
|
2014-01-03 13:32:13 -05:00
|
|
|
createVersionUrl = (versionString=null) ->
|
|
|
|
original = articles[0]._id
|
|
|
|
url = getURL("/db/article/#{original}/version")
|
|
|
|
url += ('/' + versionString) if versionString?
|
|
|
|
url
|
|
|
|
|
|
|
|
it 'can fetch the latest absolute version', (done) ->
|
|
|
|
baseUrl = createVersionUrl()
|
2014-06-30 22:16:26 -04:00
|
|
|
request.get {uri: baseUrl}, (err, res, body) ->
|
2014-01-03 13:32:13 -05:00
|
|
|
body = JSON.parse(body)
|
|
|
|
expect(res.statusCode).toBe(200)
|
|
|
|
expect(body.version.major).toBe(1)
|
|
|
|
expect(body.version.minor).toBe(0)
|
|
|
|
done()
|
|
|
|
|
|
|
|
it 'can fetch the latest major version', (done) ->
|
|
|
|
baseUrl = createVersionUrl('0')
|
2014-06-30 22:16:26 -04:00
|
|
|
request.get {uri: baseUrl}, (err, res, body) ->
|
2014-01-03 13:32:13 -05:00
|
|
|
body = JSON.parse(body)
|
|
|
|
expect(res.statusCode).toBe(200)
|
|
|
|
expect(body.version.major).toBe(0)
|
|
|
|
expect(body.version.minor).toBe(1)
|
|
|
|
done()
|
|
|
|
|
|
|
|
it 'can fetch a particular version', (done) ->
|
|
|
|
baseUrl = createVersionUrl('0.0')
|
2014-06-30 22:16:26 -04:00
|
|
|
request.get {uri: baseUrl}, (err, res, body) ->
|
2014-01-03 13:32:13 -05:00
|
|
|
body = JSON.parse(body)
|
|
|
|
expect(res.statusCode).toBe(200)
|
|
|
|
expect(body.version.major).toBe(0)
|
|
|
|
expect(body.version.minor).toBe(0)
|
|
|
|
done()
|
2014-06-30 22:16:26 -04:00
|
|
|
|
2014-01-03 13:32:13 -05:00
|
|
|
it 'returns 404 when no doc is found', (done) ->
|
|
|
|
baseUrl = createVersionUrl('3.14')
|
2014-06-30 22:16:26 -04:00
|
|
|
request.get {uri: baseUrl}, (err, res, body) ->
|
2014-01-03 13:32:13 -05:00
|
|
|
expect(res.statusCode).toBe(404)
|
|
|
|
done()
|