How do I get a nock test to pass with a post body?

Viewed 19

I have:

it.only('should trigger the Partner Client Service on error', async () => {
            const partnerServiceScope = nock(PARTNER_SERVICE_URL)
                .post('/api/v1/webhooks/event', {
                    type: 'member_info_needed',
                    data: { user_id: 'user123' },
                })
                .reply(200, {})

            try {
                await eligibilityService.getEligibility('user123')
            } catch (e) {
                expect(partnerServiceScope.isDone()).toBeTruthy()
            }
        })

The getEligibility has:

    async getEligibility(userId: string): Promise<EligibilityForPayer> {
        const eligibilityRecord =
            await stuff(userId)

        if (!eligibilityRecord) {
            void this.partnerService.postPartnerServiceEvent({
                type: PartnerServiceEventType.MemberInfoNeeded,
                data: {
                    user_id: userId,
                },
            })

The this.partnerService.postPartnerServiceEvent has:

            const res: AxiosResponse<unknown> = await partnerServiceClient.post(
                '/api/v1/webhooks/event',
                partnerServiceEvent,
            )
            return res.data

I can see that the test gets there, but the test does not return truth. What am I doing wrong?

0 Answers
Related