mirror of
https://github.com/codeninjasllc/codecombat.git
synced 2024-12-02 11:58:10 -05:00
fec3ac38e9
Admins can generate a prepaid code, which a user can use to subscribe for free via the account/subscription page. The subscription will be identical to the normal monthly subscription (e.g. 3500 gems per month), except they won’t be charged. Does not require the recipient to enter billing information. Can be applied to an existing subscription, which will be converted to free. Prepaid code can only be used once. Prepaid subscription cannot be unsubscribed via the UI.
95 lines
3.2 KiB
CoffeeScript
95 lines
3.2 KiB
CoffeeScript
require '../common'
|
|
|
|
describe '/db/prepaid', ->
|
|
prepaidURL = getURL('/db/prepaid')
|
|
prepaidCreateURL = getURL('/db/prepaid/-/create')
|
|
|
|
verifyPrepaid = (user, prepaid, done) ->
|
|
expect(prepaid.creator).toEqual(user.id)
|
|
expect(prepaid.type).toEqual('subscription')
|
|
expect(prepaid.status).toEqual('active')
|
|
expect(prepaid.code).toMatch(/^\w{8}$/)
|
|
expect(prepaid.properties?.couponID).toEqual('free')
|
|
done()
|
|
|
|
it 'Clear database users and prepaids', (done) ->
|
|
clearModels [User, Prepaid], (err) ->
|
|
throw err if err
|
|
done()
|
|
|
|
it 'Anonymous creates prepaid code', (done) ->
|
|
createPrepaid 'subscription', (err, res, body) ->
|
|
expect(err).toBeNull()
|
|
expect(res.statusCode).toBe(401)
|
|
done()
|
|
|
|
it 'Non-admin creates prepaid code', (done) ->
|
|
loginNewUser (user1) ->
|
|
expect(user1.isAdmin()).toEqual(false)
|
|
createPrepaid 'subscription', (err, res, body) ->
|
|
expect(err).toBeNull()
|
|
expect(res.statusCode).toBe(403)
|
|
done()
|
|
|
|
it 'Admin creates prepaid code with type subscription', (done) ->
|
|
loginNewUser (user1) ->
|
|
user1.set('permissions', ['admin'])
|
|
user1.save (err, user1) ->
|
|
expect(err).toBeNull()
|
|
expect(user1.isAdmin()).toEqual(true)
|
|
createPrepaid 'subscription', (err, res, body) ->
|
|
expect(err).toBeNull()
|
|
expect(res.statusCode).toBe(200)
|
|
verifyPrepaid user1, body, done
|
|
|
|
it 'Admin creates prepaid code with invalid type', (done) ->
|
|
loginNewUser (user1) ->
|
|
user1.set('permissions', ['admin'])
|
|
user1.save (err, user1) ->
|
|
expect(err).toBeNull()
|
|
expect(user1.isAdmin()).toEqual(true)
|
|
createPrepaid 'bulldozer', (err, res, body) ->
|
|
expect(err).toBeNull()
|
|
expect(res.statusCode).toBe(403)
|
|
done()
|
|
|
|
it 'Admin creates prepaid code with no type specified', (done) ->
|
|
loginNewUser (user1) ->
|
|
user1.set('permissions', ['admin'])
|
|
user1.save (err, user1) ->
|
|
expect(err).toBeNull()
|
|
expect(user1.isAdmin()).toEqual(true)
|
|
createPrepaid null, (err, res, body) ->
|
|
expect(err).toBeNull()
|
|
expect(res.statusCode).toBe(403)
|
|
done()
|
|
|
|
it 'Non-admin requests /db/prepaid', (done) ->
|
|
loginNewUser (user1) ->
|
|
expect(user1.isAdmin()).toEqual(false)
|
|
request.get {uri: prepaidURL}, (err, res, body) ->
|
|
expect(err).toBeNull()
|
|
expect(res.statusCode).toBe(403)
|
|
done()
|
|
|
|
it 'Admin requests /db/prepaid', (done) ->
|
|
loginNewUser (user1) ->
|
|
user1.set('permissions', ['admin'])
|
|
user1.save (err, user1) ->
|
|
expect(err).toBeNull()
|
|
expect(user1.isAdmin()).toEqual(true)
|
|
createPrepaid 'subscription', (err, res, prepaid) ->
|
|
expect(err).toBeNull()
|
|
expect(res.statusCode).toBe(200)
|
|
request.get {uri: prepaidURL}, (err, res, body) ->
|
|
expect(err).toBeNull()
|
|
expect(res.statusCode).toBe(200)
|
|
prepaids = JSON.parse(body)
|
|
found = false
|
|
for p in prepaids
|
|
if p._id is prepaid._id
|
|
found = true
|
|
verifyPrepaid user1, p, done
|
|
break
|
|
expect(found).toEqual(true)
|
|
done() unless found
|