Просмотр исходного кода

Add additional tests for V1SubscriptionManager

One call was not returning the v1Id correctly. These tests check for that case. Also added some more generic tests for the v1 API call.

bug: overleaf/sharelatex#1014
Simon Detheridge 8 лет назад
Родитель
Сommit
0f54bc2c52

+ 1 - 1
services/web/app/coffee/Features/Subscription/V1SubscriptionManager.coffee

@@ -66,7 +66,7 @@ module.exports = V1SubscriptionManager =
 
 
 		V1SubscriptionManager.v1IdForUser userId, (err, v1Id) ->
 		V1SubscriptionManager.v1IdForUser userId, (err, v1Id) ->
 			return callback(err) if err?
 			return callback(err) if err?
-			return callback(null, null) if !v1Id?
+			return callback(null, null, null) if !v1Id?
 			request {
 			request {
 				baseUrl: settings.apis.v1.url
 				baseUrl: settings.apis.v1.url
 				url: options.url(v1Id)
 				url: options.url(v1Id)

+ 41 - 0
services/web/test/unit/coffee/Subscription/V1SusbcriptionManagerTests.coffee

@@ -55,6 +55,11 @@ describe 'V1SubscriptionManager', ->
 					).to.equal true
 					).to.equal true
 					done()
 					done()
 
 
+			it 'should return the v1 user id', (done) ->
+				@call (err, planCode, v1Id) ->
+					expect(v1Id).to.equal @v1UserId
+					done()
+
 			it 'should produce a plan-code without error', (done) ->
 			it 'should produce a plan-code without error', (done) ->
 				@call (err, planCode) =>
 				@call (err, planCode) =>
 					expect(err).to.not.exist
 					expect(err).to.not.exist
@@ -138,6 +143,42 @@ describe 'V1SubscriptionManager', ->
 					expect(err).to.exist
 					expect(err).to.exist
 					done()
 					done()
 
 
+		describe 'when the call succeeds', ->
+			beforeEach ->
+				@V1SubscriptionManager.v1IdForUser = sinon.stub()
+					.yields(null, @v1UserId)
+				@request.yields(null, { statusCode: 200 }, "{}")
+				@call = (cb) =>
+					@V1SubscriptionManager._v1Request @user_id, { url: () -> '/foo' }, cb
+
+			it 'should not produce an error', (done) ->
+				@call (err, body, v1Id) =>
+					expect(err).not.to.exist
+					done()
+
+			it 'should return the v1 user id', (done) ->
+				@call (err, body, v1Id) =>
+					expect(v1Id).to.equal @v1UserId
+					done()
+
+			it 'should return the http response body', (done) ->
+				@call (err, body, v1Id) =>
+					expect(body).to.equal "{}"
+					done()
+
+		describe 'when the call returns an http error status code', ->
+			beforeEach ->
+				@V1SubscriptionManager.v1IdForUser = sinon.stub()
+					.yields(null, @v1UserId)
+				@request.yields(null, { statusCode: 500 }, "{}")
+				@call = (cb) =>
+					@V1SubscriptionManager._v1Request @user_id, { url: () -> '/foo' }, cb
+
+			it 'should produce an error', (done) ->
+				@call (err, body, v1Id) =>
+					expect(err).to.exist
+					done()
+
 	describe 'v1IdForUser', ->
 	describe 'v1IdForUser', ->
 		beforeEach ->
 		beforeEach ->
 			@UserGetter.getUser = sinon.stub()
 			@UserGetter.getUser = sinon.stub()