-
Notifications
You must be signed in to change notification settings - Fork 0
OUT-4030: warn IUs which mixed-payout fees are already recorded #280
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
dd740c2
feat(OUT-4030): add ground-truth lookup for invoices with a recorded fee
SandipBajracharya dafd922
feat(OUT-4030): warn IUs which mixed-payout fees are already recorded
SandipBajracharya 95069fe
refactor(OUT-4030): extract mixed-payout invoice resolution into a he…
SandipBajracharya File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
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
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
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
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
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
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,36 @@ | ||
| 'use server' | ||
| import { EntityType, EventType, LogStatus } from '@/app/api/core/types/log' | ||
| import { db } from '@/db' | ||
| import { QBSyncLog } from '@/db/schema/qbSyncLogs' | ||
| import { and, eq, inArray, isNull } from 'drizzle-orm' | ||
|
|
||
| // Which of these invoices already have a recorded absorbed-fee expense in QBO. | ||
| // A SUCCESS PAYMENT/SUCCEEDED row exists only if the fee Purchase was created. | ||
| export const getInvoiceNumbersWithRecordedFee = async ( | ||
| portalId: string, | ||
| invoiceNumbers: string[], | ||
| ): Promise<Set<string>> => { | ||
| if (invoiceNumbers.length === 0) return new Set() | ||
|
|
||
| const rows = await db | ||
| .select({ invoiceNumber: QBSyncLog.invoiceNumber }) | ||
| .from(QBSyncLog) | ||
| .where( | ||
| and( | ||
| eq(QBSyncLog.portalId, portalId), | ||
| eq(QBSyncLog.entityType, EntityType.PAYMENT), | ||
| eq(QBSyncLog.eventType, EventType.SUCCEEDED), | ||
| eq(QBSyncLog.status, LogStatus.SUCCESS), | ||
| inArray(QBSyncLog.invoiceNumber, invoiceNumbers), | ||
| isNull(QBSyncLog.deletedAt), | ||
| ), | ||
| ) | ||
|
|
||
| return new Set( | ||
| rows | ||
| .map((row) => row.invoiceNumber) | ||
| .filter((invoiceNumber): invoiceNumber is string => | ||
| Boolean(invoiceNumber), | ||
| ), | ||
| ) | ||
| } |
93 changes: 93 additions & 0 deletions
93
test/integration/quickbooks/syncLog/getInvoiceNumbersWithRecordedFee.test.ts
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,93 @@ | ||
| import { describe, expect, it, beforeEach } from 'vitest' | ||
|
|
||
| import { EntityType, EventType, LogStatus } from '@/app/api/core/types/log' | ||
| import { db } from '@/db' | ||
| import { QBSyncLog } from '@/db/schema/qbSyncLogs' | ||
| import { getInvoiceNumbersWithRecordedFee } from '@/db/service/syncLog.service' | ||
| import { TEST_PORTAL_ID } from '@test/helpers/seed' | ||
| import { truncateAllTestTables } from '@test/helpers/testDb' | ||
|
|
||
| const OTHER_PORTAL_ID = 'portal-other-0001' | ||
|
|
||
| type LogSeed = { | ||
| invoiceNumber: string | ||
| portalId?: string | ||
| entityType?: EntityType | ||
| eventType?: EventType | ||
| status?: LogStatus | ||
| deletedAt?: Date | null | ||
| } | ||
|
|
||
| const seedLog = (seed: LogSeed) => | ||
| db.insert(QBSyncLog).values({ | ||
| portalId: seed.portalId ?? TEST_PORTAL_ID, | ||
| copilotId: `pay_${seed.invoiceNumber}`, | ||
| entityType: seed.entityType ?? EntityType.PAYMENT, | ||
| eventType: seed.eventType ?? EventType.SUCCEEDED, | ||
| status: seed.status ?? LogStatus.SUCCESS, | ||
| invoiceNumber: seed.invoiceNumber, | ||
| deletedAt: seed.deletedAt ?? null, | ||
| }) | ||
|
|
||
| describe('getInvoiceNumbersWithRecordedFee', () => { | ||
| beforeEach(async () => { | ||
| await truncateAllTestTables() | ||
| }) | ||
|
|
||
| it('returns invoices that have a SUCCESS PAYMENT/SUCCEEDED log', async () => { | ||
| await seedLog({ invoiceNumber: 'INV-A' }) | ||
| await seedLog({ invoiceNumber: 'INV-B' }) | ||
|
|
||
| const recorded = await getInvoiceNumbersWithRecordedFee(TEST_PORTAL_ID, [ | ||
| 'INV-A', | ||
| 'INV-B', | ||
| ]) | ||
|
|
||
| expect(recorded).toEqual(new Set(['INV-A', 'INV-B'])) | ||
| }) | ||
|
|
||
| it('only counts the recorded ones, ignoring the rest of the requested list', async () => { | ||
| await seedLog({ invoiceNumber: 'INV-A' }) | ||
|
|
||
| const recorded = await getInvoiceNumbersWithRecordedFee(TEST_PORTAL_ID, [ | ||
| 'INV-A', | ||
| 'INV-B', | ||
| ]) | ||
|
|
||
| expect(recorded).toEqual(new Set(['INV-A'])) | ||
| }) | ||
|
|
||
| it('excludes non-SUCCESS, wrong entity/event, soft-deleted, and other-portal rows', async () => { | ||
| await seedLog({ invoiceNumber: 'INV-OK' }) | ||
| await seedLog({ invoiceNumber: 'INV-FAILED', status: LogStatus.FAILED }) | ||
| await seedLog({ | ||
| invoiceNumber: 'INV-WRONG-EVENT', | ||
| eventType: EventType.CREATED, | ||
| }) | ||
| await seedLog({ | ||
| invoiceNumber: 'INV-WRONG-ENTITY', | ||
| entityType: EntityType.INVOICE, | ||
| }) | ||
| await seedLog({ invoiceNumber: 'INV-DELETED', deletedAt: new Date() }) | ||
| await seedLog({ invoiceNumber: 'INV-OTHER', portalId: OTHER_PORTAL_ID }) | ||
|
|
||
| const recorded = await getInvoiceNumbersWithRecordedFee(TEST_PORTAL_ID, [ | ||
| 'INV-OK', | ||
| 'INV-FAILED', | ||
| 'INV-WRONG-EVENT', | ||
| 'INV-WRONG-ENTITY', | ||
| 'INV-DELETED', | ||
| 'INV-OTHER', | ||
| ]) | ||
|
|
||
| expect(recorded).toEqual(new Set(['INV-OK'])) | ||
| }) | ||
|
|
||
| it('returns an empty set for empty input', async () => { | ||
| await seedLog({ invoiceNumber: 'INV-A' }) | ||
|
|
||
| const recorded = await getInvoiceNumbersWithRecordedFee(TEST_PORTAL_ID, []) | ||
|
|
||
| expect(recorded).toEqual(new Set()) | ||
| }) | ||
| }) |
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
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.