async function testDiscount({discount, interval, unit_amount, assert_mrr, offer_id}) {
            const customer_id = createStripeID('cust');
            const subscription_id = createStripeID('sub');

            discount.customer = customer_id;

            set(subscription, {
                id: subscription_id,
                customer: customer_id,
                status: 'active',
                discount,
                items: {
                    type: 'list',
                    data: [{
                        id: 'item_123',
                        price: {
                            id: 'price_123',
                            product: 'product_123',
                            active: true,
                            nickname: interval,
                            currency: 'usd',
                            recurring: {
                                interval
                            },
                            unit_amount,
                            type: 'recurring'
                        }
                    }]
                },
                start_date: beforeNow / 1000,
                current_period_end: Math.floor(beforeNow / 1000) + (60 * 60 * 24 * 31),
                cancel_at_period_end: false,
                metadata: {}
            });

            set(customer, {
                id: customer_id,
                name: 'Test Member',
                email: `${customer_id}@email.com`,
                subscriptions: {
                    type: 'list',
                    data: [subscription]
                }
            });

            let webhookPayload = JSON.stringify({
                type: 'checkout.session.completed',
                data: {
                    object: {
                        mode: 'subscription',
                        customer: customer.id,
                        subscription: subscription.id,
                        metadata: {}
                    }
                }
            });

            let webhookSignature = stripe.webhooks.generateTestHeaderString({
                payload: webhookPayload,
                secret: process.env.WEBHOOK_SECRET
            });

            await membersAgent.post('/webhooks/stripe/')
                .body(webhookPayload)
                .header('content-type', 'application/json')
                .header('stripe-signature', webhookSignature)
                .expectStatus(200);

            const {body} = await adminAgent.get(`/members/?search=${customer_id}@email.com`);
            assert.equal(body.members.length, 1, 'The member was not created');
            const member = body.members[0];

            assert.equal(member.status, 'paid', 'The member should be "paid"');
            assert.equal(member.subscriptions.length, 1, 'The member should have a single subscription');

            // Check whether MRR and status has been set
            await assertSubscription(member.subscriptions[0].id, {
                subscription_id: subscription.id,
                status: 'active',
                cancel_at_period_end: false,
                plan_amount: unit_amount,
                plan_interval: interval,
                plan_currency: 'usd',
                current_period_end: new Date(Math.floor(beforeNow / 1000) * 1000 + (60 * 60 * 24 * 31 * 1000)),
                mrr: assert_mrr,
                offer_id: offer_id
            });

            // Check whether the offer attribute is passed correctly in the response when fetching a single member
            member.subscriptions[0].should.match({
                offer: {
                    id: offer_id
                }
            });

            await assertMemberEvents({
                eventType: 'MemberPaidSubscriptionEvent',
                memberId: member.id,
                asserts: [
                    {
                        mrr_delta: assert_mrr
                    }
                ]
            });

            // Now cancel, and check if the discount is also applied for the cancellation
            set(subscription, {
                ...subscription,
                status: 'canceled'
            });

            // Send the webhook call to announce the cancelation
            webhookPayload = JSON.stringify({
                type: 'customer.subscription.updated',
                data: {
                    object: subscription
                }
            });

            webhookSignature = stripe.webhooks.generateTestHeaderString({
                payload: webhookPayload,
                secret: process.env.WEBHOOK_SECRET
            });

            await membersAgent.post('/webhooks/stripe/')
                .body(webhookPayload)
                .header('content-type', 'application/json')
                .header('stripe-signature', webhookSignature)
                .expectStatus(200);

            // Check status has been updated to 'free' after cancelling
            const {body: body2} = await adminAgent.get('/members/' + member.id + '/');
            assert.equal(body2.members.length, 1, 'The member does not exist');
            const updatedMember = body2.members[0];
            assert.equal(updatedMember.status, 'free');
            assert.equal(updatedMember.tiers.length, 0, 'The member should have no products');
            should(updatedMember.subscriptions).match([
                {
                    status: 'canceled',
                    offer: {
                        id: offer_id
                    }
                }
            ]);

            // Check whether MRR and status has been set
            await assertSubscription(member.subscriptions[0].id, {
                subscription_id: subscription.id,
                status: 'canceled',
                cancel_at_period_end: false,
                plan_amount: unit_amount,
                plan_interval: interval,
                plan_currency: 'usd',
                mrr: 0,
                offer_id: offer_id
            });

            await assertMemberEvents({
                eventType: 'MemberPaidSubscriptionEvent',
                memberId: updatedMember.id,
                asserts: [
                    {
                        type: 'created',
                        mrr_delta: assert_mrr
                    },
                    {
                        type: 'expired',
                        mrr_delta: -assert_mrr
                    }
                ]
            });
        }
Helper for repetitive tests. It tests the MRR and MRR delta given a discount + a price