test.js

 avatar
unknown
javascript
2 years ago
1.3 kB
4
Indexable
import { LoyaltyDiscountService } from './loyaltyDiscount.service';

import { expect, jest, it, describe, afterEach } from '@jest/globals';

jest.mock('./loyaltyDiscount.repository', () => {
    return jest.fn().mockImplementation(() => {
        return {
            getDiscountInfo: jest.fn(() => {
                return {
                    id: 11096,
                    username: '',
                    email: '',
                    discountAmount: 0,
                    discountLevel: 17.11,
                    media: '+13642044867',
                    mediaType: 'phone',
                    partnerId: 270,
                };
            }),
        };
    });
});
describe('Test Loyalty Discount Service', () => {
    afterEach(() => {
        jest.restoreAllMocks();
    });

    it('Should return Discount Info', async () => {
        const loyaltyDiscountService = new LoyaltyDiscountService();
        const resp = await loyaltyDiscountService.getDiscountInfo({
            media: '+13642044867',
            partnerId: '270',
        });

        const ldRepoSpy = jest.spyOn(loyaltyDiscountService.loyaltyDiscountRepo, 'getDiscountInfo');

        expect(resp).toMatchObject({ mediaId: '+13642044867' });
        expect(ldRepoSpy).toHaveBeenCalled();
    });
});
Editor is loading...