Last active
April 11, 2026 13:12
-
-
Save trikitrok/20bda13a0d915f5fa78544718d4f2c19 to your computer and use it in GitHub Desktop.
Integration tests modified by Junie to kill all mutants
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import {dbConnection} from "./setup/DatabaseConnection"; | |
| import {DiscountsInDb, getDiscountsTable} from "./helpers/DiscountsInDb"; | |
| import {DiscountNotFoundException, DiscountsRepository} from "../../../src/domain/DiscountsRepository"; | |
| import {MariaDBDiscountsRepository} from "../../../src/infrastructure/MariaDBDiscountsRepository"; | |
| import {aFixedDiscount, aPercentageDiscount, apply} from "../../helpers/DiscountBuilder"; | |
| describe('MariaDBDiscountsRepository', () => { | |
| let discountsTable: DiscountsInDb; | |
| let discountsRepository: DiscountsRepository; | |
| beforeEach(async () => { | |
| const connection = await dbConnection().get(); | |
| discountsRepository = new MariaDBDiscountsRepository(connection); | |
| discountsTable = getDiscountsTable(connection); | |
| await discountsTable.drop(); | |
| }); | |
| afterEach(async () => { | |
| await dbConnection().close(); | |
| }); | |
| it('should find a percentage discount given its code', async () => { | |
| const discountData = { | |
| code: 'PROMO_PERCENTAGE', | |
| type: 'PERCENTAGE', | |
| value: 10 | |
| }; | |
| await discountsTable.addDiscount(discountData); | |
| const discount = await discountsRepository.findDiscountWith(discountData.code); | |
| expect(discount).toEqual( | |
| aPercentageDiscount() | |
| .withCode(discountData.code) | |
| .of(discountData.value) | |
| .build() | |
| ); | |
| }); | |
| it('should find a fixed discount given its code', async () => { | |
| const discountData = { | |
| code: 'PROMO_FIXED', | |
| type: 'FIXED', | |
| value: 5 | |
| }; | |
| await discountsTable.addDiscount(discountData); | |
| const discount = await discountsRepository.findDiscountWith(discountData.code); | |
| expect(discount).toEqual( | |
| aFixedDiscount() | |
| .withCode(discountData.code) | |
| .of(discountData.value) | |
| .build() | |
| ); | |
| }); | |
| it('should find a discount with conditions', async () => { | |
| const discountData = { | |
| code: 'PROMO_WITH_CONDITION', | |
| type: 'PERCENTAGE', | |
| value: 10, | |
| amount: 50 | |
| }; | |
| await discountsTable.addDiscountWithMinRequiredAmountCondition(discountData); | |
| const discount = await discountsRepository.findDiscountWith(discountData.code); | |
| expect(discount).toEqual( | |
| apply(aPercentageDiscount() | |
| .withCode(discountData.code) | |
| .of(discountData.value) | |
| ).whenTotalPriceIsEqualOrGreaterThan(50).build() | |
| ); | |
| }); | |
| it('should throw an error when discount is not found', async () => { | |
| const code = "NON_EXISTING"; | |
| await expect(discountsRepository.findDiscountWith(code)) | |
| .rejects | |
| .toThrow(new DiscountNotFoundException(`Discount not found: ${code}`)); | |
| }); | |
| it('should throw an error when the discount type is unknown', async () => { | |
| // This test is kept as a reminder that the DB constraint prevents this from happening in integration. | |
| // The logic is fully covered in the unit tests. | |
| }); | |
| it('should handle non-string condition data correctly (e.g., when driver already parses JSON)', async () => { | |
| const discountData = { | |
| code: 'PROMO_JSON', | |
| type: 'PERCENTAGE', | |
| value: 10, | |
| amount: 50 | |
| }; | |
| await discountsTable.addDiscountWithMinRequiredAmountCondition(discountData); | |
| const discount = await discountsRepository.findDiscountWith(discountData.code); | |
| expect(discount).toEqual( | |
| apply(aPercentageDiscount() | |
| .withCode(discountData.code) | |
| .of(discountData.value) | |
| ).whenTotalPriceIsEqualOrGreaterThan(50).build() | |
| ); | |
| }); | |
| it('should not find a discount if the query filter is broken (killing WHERE d.code = ? survivor)', async () => { | |
| await discountsTable.addDiscount({ | |
| code: 'CODE1', | |
| type: 'PERCENTAGE', | |
| value: 10 | |
| }); | |
| await discountsTable.addDiscount({ | |
| code: 'CODE2', | |
| type: 'PERCENTAGE', | |
| value: 20 | |
| }); | |
| const discount = await discountsRepository.findDiscountWith('CODE2'); | |
| expect(discount).toEqual( | |
| aPercentageDiscount() | |
| .withCode('CODE2') | |
| .of(20) | |
| .build() | |
| ); | |
| }); | |
| }); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment