Skip to content

Commit

Permalink
Fix types in filter comparison, expose INVOICE_EVENT_TIMESTAMP_TYPES …
Browse files Browse the repository at this point in the history
…for test (unfortunately)
  • Loading branch information
tkaemming committed Mar 14, 2024
1 parent b9f0ee2 commit 7ddd52a
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 4 deletions.
3 changes: 2 additions & 1 deletion index.test.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { getMeta, resetMeta } from '@posthog/plugin-scaffold/test/utils.js'
import { setupPlugin, jobs, runEveryMinute } from './index'
import { setupPlugin, jobs, runEveryMinute, INVOICE_EVENT_TIMESTAMP_TYPES } from './index'
import 'jest'

global.fetch = jest.fn(async (url) => ({
Expand Down Expand Up @@ -43,6 +43,7 @@ beforeEach(() => {
posthog.api.get.mockClear()
global.groupType = undefined
global.groupTypeIndex = undefined
global.getInvoiceTimestamp = INVOICE_EVENT_TIMESTAMP_TYPES['Invoice Period End Date']

mockStorage = new Map()
storage = {
Expand Down
6 changes: 3 additions & 3 deletions index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ interface StoredInvoice {
}

// Keep this in sync with the `invoiceEventTimestamp` choices in config.json!
const INVOICE_EVENT_TIMESTAMP_TYPES: Record<string, (invoice: StoredInvoice) => Date | undefined> = {
export const INVOICE_EVENT_TIMESTAMP_TYPES: Record<string, (invoice: StoredInvoice) => Date | undefined> = {
'Invoice Period End Date': (invoice) => new Date(invoice.period_end * 1000),
'Invoice Payment Date': (invoice) => {
// older invoices may have been written without state transition data
Expand Down Expand Up @@ -99,8 +99,8 @@ async function sendGroupEvent(invoice, customer, due_last_month, due_total, paid

function last_month(global, invoices: StoredInvoice[], key) {
const today = new Date()
const firstDayThisMonth = Math.floor(new Date(today.getFullYear(), today.getMonth(), 1) / 1000)
const firstDayNextMonth = Math.floor(new Date(today.getFullYear(), today.getMonth() + 1, 1) / 1000)
const firstDayThisMonth = new Date(today.getFullYear(), today.getMonth(), 1)
const firstDayNextMonth = new Date(today.getFullYear(), today.getMonth() + 1, 1)
return invoices
.filter((invoice) => {
const timestamp = global.getInvoiceTimestamp(invoice)
Expand Down

0 comments on commit 7ddd52a

Please sign in to comment.