mirror of
https://github.com/codeninjasllc/codecombat.git
synced 2024-11-27 17:45:40 -05:00
Finished Article tests to demonstrate search functionality
This commit is contained in:
parent
0751581113
commit
fef72d8273
2 changed files with 27 additions and 12 deletions
|
@ -23,7 +23,7 @@ module.exports.PatchablePlugin = (schema) ->
|
||||||
schema.is_patchable = true
|
schema.is_patchable = true
|
||||||
schema.index({'target.original':1, 'status':'1', 'created':-1})
|
schema.index({'target.original':1, 'status':'1', 'created':-1})
|
||||||
|
|
||||||
RESERVED_NAMES = ['search', 'names']
|
RESERVED_NAMES = ['names']
|
||||||
|
|
||||||
module.exports.NamedPlugin = (schema) ->
|
module.exports.NamedPlugin = (schema) ->
|
||||||
schema.uses_coco_names = true
|
schema.uses_coco_names = true
|
||||||
|
|
|
@ -8,6 +8,8 @@ describe '/db/article', ->
|
||||||
done()
|
done()
|
||||||
|
|
||||||
article = {name: 'Yo', body:'yo ma'}
|
article = {name: 'Yo', body:'yo ma'}
|
||||||
|
article2 = {name: 'Original', body:'yo daddy'}
|
||||||
|
|
||||||
url = getURL('/db/article')
|
url = getURL('/db/article')
|
||||||
articles = {}
|
articles = {}
|
||||||
|
|
||||||
|
@ -27,11 +29,22 @@ describe '/db/article', ->
|
||||||
expect(body.original).toBeDefined()
|
expect(body.original).toBeDefined()
|
||||||
expect(body.creator).toBeDefined()
|
expect(body.creator).toBeDefined()
|
||||||
articles[0] = body
|
articles[0] = body
|
||||||
|
|
||||||
|
# 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()
|
done()
|
||||||
|
|
||||||
it 'allows admins to make new minor versions', (done) ->
|
it 'allows admins to make new minor versions', (done) ->
|
||||||
new_article = _.clone(articles[0])
|
new_article = _.clone(articles[0])
|
||||||
new_article.body = '...'
|
new_article.body = 'yo daddy'
|
||||||
request.post {uri:url, json:new_article}, (err, res, body) ->
|
request.post {uri:url, json:new_article}, (err, res, body) ->
|
||||||
expect(res.statusCode).toBe(200)
|
expect(res.statusCode).toBe(200)
|
||||||
expect(body.version.major).toBe(0)
|
expect(body.version.major).toBe(0)
|
||||||
|
@ -62,7 +75,6 @@ describe '/db/article', ->
|
||||||
expect(body.body).toBe(articles[0].body)
|
expect(body.body).toBe(articles[0].body)
|
||||||
done()
|
done()
|
||||||
|
|
||||||
|
|
||||||
it 'does not allow regular users to make new versions', (done) ->
|
it 'does not allow regular users to make new versions', (done) ->
|
||||||
new_article = _.clone(articles[2])
|
new_article = _.clone(articles[2])
|
||||||
request.post {uri:url, json:new_article}, (err, res, body) ->
|
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) ->
|
it 'does not allow naming an article a reserved word', (done) ->
|
||||||
loginAdmin ->
|
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) ->
|
request.post {uri:url, json:new_article}, (err, res, body) ->
|
||||||
expect(res.statusCode).toBe(422)
|
expect(res.statusCode).toBe(422)
|
||||||
done()
|
done()
|
||||||
|
|
||||||
it 'allows regular users to get all articles', (done) ->
|
it 'allows regular users to get all articles', (done) ->
|
||||||
loginJoe ->
|
loginJoe ->
|
||||||
request.get {uri:url}, (err, res, body) ->
|
request.get {uri:url, json:{}}, (err, res, body) ->
|
||||||
expect(res.statusCode).toBe(200)
|
expect(res.statusCode).toBe(200)
|
||||||
expect(body.length).toBe(2)
|
expect(body.length).toBe(2)
|
||||||
|
done()
|
||||||
|
|
||||||
it 'allows regular users to get articles and use projection', (done) ->
|
it 'allows regular users to get articles and use projection', (done) ->
|
||||||
loginJoe ->
|
loginJoe ->
|
||||||
# default projection
|
# 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(res.statusCode).toBe(200)
|
||||||
expect(body.length).toBe(2)
|
expect(body.length).toBe(2)
|
||||||
expect(body[0].created?).toBeUndefined()
|
expect(body[0].created).toBeUndefined()
|
||||||
expect(body[0].version?).toBeDefined()
|
expect(body[0].version).toBeDefined()
|
||||||
|
|
||||||
# custom projection
|
# 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(res.statusCode).toBe(200)
|
||||||
expect(body.length).toBe(2)
|
expect(body.length).toBe(2)
|
||||||
expect(Object.keys(body[0]).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) ->
|
it 'allows regular users to perform a text search', (done) ->
|
||||||
loginJoe ->
|
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(res.statusCode).toBe(200)
|
||||||
expect(body.length).toBe(1)
|
expect(body.length).toBe(1)
|
||||||
# expect name blabla
|
expect(body[0].name).toBe(article2.name)
|
||||||
|
expect(body[0].body).toBe(article2.body)
|
||||||
done()
|
done()
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue