Finished Article tests to demonstrate search functionality

This commit is contained in:
Ruben Vereecken 2014-06-12 19:19:18 +02:00
parent 0751581113
commit fef72d8273
2 changed files with 27 additions and 12 deletions

View file

@ -23,7 +23,7 @@ module.exports.PatchablePlugin = (schema) ->
schema.is_patchable = true
schema.index({'target.original':1, 'status':'1', 'created':-1})
RESERVED_NAMES = ['search', 'names']
RESERVED_NAMES = ['names']
module.exports.NamedPlugin = (schema) ->
schema.uses_coco_names = true

View file

@ -8,6 +8,8 @@ describe '/db/article', ->
done()
article = {name: 'Yo', body:'yo ma'}
article2 = {name: 'Original', body:'yo daddy'}
url = getURL('/db/article')
articles = {}
@ -27,11 +29,22 @@ describe '/db/article', ->
expect(body.original).toBeDefined()
expect(body.creator).toBeDefined()
articles[0] = body
done()
# Having two articles allow for testing article search and such
request.post {uri:url, json:article2}, (err, res, body) ->
expect(res.statusCode).toBe(200)
expect(body.slug).toBeDefined()
expect(body.body).toBeDefined()
expect(body.name).toBeDefined()
expect(body.original).toBeDefined()
expect(body.creator).toBeDefined()
articles[0] = body
done()
it 'allows admins to make new minor versions', (done) ->
new_article = _.clone(articles[0])
new_article.body = '...'
new_article.body = 'yo daddy'
request.post {uri:url, json:new_article}, (err, res, body) ->
expect(res.statusCode).toBe(200)
expect(body.version.major).toBe(0)
@ -62,7 +75,6 @@ describe '/db/article', ->
expect(body.body).toBe(articles[0].body)
done()
it 'does not allow regular users to make new versions', (done) ->
new_article = _.clone(articles[2])
request.post {uri:url, json:new_article}, (err, res, body) ->
@ -87,28 +99,29 @@ describe '/db/article', ->
it 'does not allow naming an article a reserved word', (done) ->
loginAdmin ->
new_article = {name: 'Search', body:'is a reserved word'}
new_article = {name: 'Names', body:'is a reserved word'}
request.post {uri:url, json:new_article}, (err, res, body) ->
expect(res.statusCode).toBe(422)
done()
it 'allows regular users to get all articles', (done) ->
loginJoe ->
request.get {uri:url}, (err, res, body) ->
request.get {uri:url, json:{}}, (err, res, body) ->
expect(res.statusCode).toBe(200)
expect(body.length).toBe(2)
done()
it 'allows regular users to get articles and use projection', (done) ->
loginJoe ->
# default projection
request.get {uri:url + '?project=true'}, (err, res, body) ->
request.get {uri:url + '?project=true', json:{}}, (err, res, body) ->
expect(res.statusCode).toBe(200)
expect(body.length).toBe(2)
expect(body[0].created?).toBeUndefined()
expect(body[0].version?).toBeDefined()
expect(body[0].created).toBeUndefined()
expect(body[0].version).toBeDefined()
# custom projection
request.get {uri:url + '?project=original'}, (err, res, body) ->
request.get {uri:url + '?project=original', json:{}}, (err, res, body) ->
expect(res.statusCode).toBe(200)
expect(body.length).toBe(2)
expect(Object.keys(body[0]).length).toBe(2)
@ -117,8 +130,10 @@ describe '/db/article', ->
it 'allows regular users to perform a text search', (done) ->
loginJoe ->
request.get {uri:url + 'term="friend"'}, (err, res, body) ->
request.get {uri:url + '?term="daddy"', json:{}}, (err, res, body) ->
expect(res.statusCode).toBe(200)
expect(body.length).toBe(1)
# expect name blabla
expect(body[0].name).toBe(article2.name)
expect(body[0].body).toBe(article2.body)
done()