 		it "should be signed correctly", ->
 			signed = @signature.split("|")[0]
 			query = @signature.split("|")[1]
-			crypto.createHmac("sha1", Settings.apis.recurly.privateKey).update(query).digest("hex").should.equal signed
+			crypto.createHmac("sha1", @settings.apis.recurly.privateKey).update(query).digest("hex").should.equal signed
 
 		it "should be url escaped", ->
 			query = @signature.split("|")[1]


		describe "with includeAccount", ->
			beforeEach ->
				@apiRequest = sinon.stub(RecurlyWrapper, "apiRequest", mockApiRequest)
				RecurlyWrapper.getSubscription "44f83d7cba354d5b84812419f923ea96", {includeAccount: true}, (error, recurlySubscription) =>
					@recurlySubscription = recurlySubscription
			afterEach ->
				RecurlyWrapper.apiRequest.restore()

			it "should request the account from the API", ->
				@apiRequest.args[1][0].url.should.equal "accounts/104"
				
			it "should populate the account attribute", ->
				@recurlySubscription.account.account_code.should.equal "104"
			

	describe "updateSubscription", ->
		beforeEach (done) ->
			@recurlySubscriptionId = "subscription-id-123"
			@apiRequest = sinon.stub RecurlyWrapper, "apiRequest", (options, callback) =>
				@requestOptions = options
				callback null, {}, fixtures["subscriptions/44f83d7cba354d5b84812419f923ea96"]
			RecurlyWrapper.updateSubscription @recurlySubscriptionId, { plan_code : "silver", timeframe: "now" }, (error, recurlySubscription) =>
				@recurlySubscription = recurlySubscription
				done()
		afterEach ->
			RecurlyWrapper.apiRequest.restore()

		it "should send an update request to the API", ->
			@apiRequest.called.should.equal true



describe "RecurlyWrapper", ->

	before ->
		@settings =
			plans: [{
				planCode: "collaborator"
				name: "Collaborator"
				features:
					collaborators: -1
					versioning: true
			}]
			defaultPlanCode:
				collaborators: 0
				versioning: false
			apis:
				recurly:
					apiKey: 'nonsense'
					privateKey: 'private_nonsense'

		@RecurlyWrapper = RecurlyWrapper = SandboxedModule.require modulePath, requires:
			"settings-sharelatex": @settings
			"logger-sharelatex":
				err:   sinon.stub()
				error: sinon.stub()
				log:   sinon.stub()
			"request": sinon.stub()

	describe "sign", ->

		before (done) ->
			tk.freeze Date.now() # freeze the time for these tests
			@RecurlyWrapper.sign({
				subscription :
					plan_code : "gold"
					name      : "$$$"
