Răsfoiți Sursa

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 ani în urmă
părinte
comite
0f54bc2c52

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

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

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

@@ -55,6 +55,11 @@ describe 'V1SubscriptionManager', ->
 					).to.equal true
 					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) ->
 				@call (err, planCode) =>
 					expect(err).to.not.exist
@@ -138,6 +143,42 @@ describe 'V1SubscriptionManager', ->
 					expect(err).to.exist
 					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', ->
 		beforeEach ->
 			@UserGetter.getUser = sinon.stub()