|
@@ -1,3 +1,4 @@
|
|
|
|
|
+import { realmRef } from '@/integrations/quickbooks/mapping'
|
|
|
import { beforeEach, describe, expect, it, vi } from 'vitest'
|
|
import { beforeEach, describe, expect, it, vi } from 'vitest'
|
|
|
import type {
|
|
import type {
|
|
|
AccountingCustomer,
|
|
AccountingCustomer,
|
|
@@ -93,7 +94,7 @@ function makeCtx(input: {
|
|
|
state,
|
|
state,
|
|
|
externalAccountId: '9130357',
|
|
externalAccountId: '9130357',
|
|
|
},
|
|
},
|
|
|
- credentials: { accessToken: 'tok', refreshToken: 'ref' },
|
|
|
|
|
|
|
+ credentials: { accessToken: 'tok', refreshToken: 'ref', realmId: '9130357' },
|
|
|
http: {
|
|
http: {
|
|
|
fetch: async () => {
|
|
fetch: async () => {
|
|
|
throw new Error('not used')
|
|
throw new Error('not used')
|
|
@@ -1025,7 +1026,8 @@ describe('QuickBooks: connecting', () => {
|
|
|
},
|
|
},
|
|
|
})
|
|
})
|
|
|
const who = await connector.identify?.(t.ctx)
|
|
const who = await connector.identify?.(t.ctx)
|
|
|
- expect(who).toEqual({ id: '9130357', name: 'Sandbox Garage Ltd (sandbox)' })
|
|
|
|
|
|
|
+ expect(who).toEqual({ id: realmRef('9130357'), name: 'Sandbox Garage Ltd (sandbox)' })
|
|
|
|
|
+ expect(who?.id).not.toContain('9130357')
|
|
|
expect(t.state).toMatchObject({
|
|
expect(t.state).toMatchObject({
|
|
|
environment: 'sandbox',
|
|
environment: 'sandbox',
|
|
|
country: 'GB',
|
|
country: 'GB',
|
|
@@ -1040,6 +1042,17 @@ describe('QuickBooks: connecting', () => {
|
|
|
expect(t.calls.at(-1)?.host).toBe('sandbox-quickbooks.api.intuit.com')
|
|
expect(t.calls.at(-1)?.host).toBe('sandbox-quickbooks.api.intuit.com')
|
|
|
})
|
|
})
|
|
|
|
|
|
|
|
|
|
+ it('reads the company from the sealed credentials, falling back to older state', async () => {
|
|
|
|
|
+ const fresh = makeCtx({ state: { realmId: undefined }, answer: emptyCompany() })
|
|
|
|
|
+ await connector.jobs['accounting.invoice'](fresh.ctx, { entityId: 'svc1' })
|
|
|
|
|
+ expect(fresh.calls[0].path).toBe('/v3/company/9130357/query')
|
|
|
|
|
+
|
|
|
|
|
+ const legacy = makeCtx({ answer: emptyCompany() })
|
|
|
|
|
+ legacy.ctx.credentials = { accessToken: 'tok', refreshToken: 'ref' }
|
|
|
|
|
+ await connector.jobs['accounting.invoice'](legacy.ctx, { entityId: 'svc1' })
|
|
|
|
|
+ expect(legacy.calls[0].path).toBe('/v3/company/9130357/query')
|
|
|
|
|
+ })
|
|
|
|
|
+
|
|
|
it('recognises automated sales tax and says when sales tax is off', async () => {
|
|
it('recognises automated sales tax and says when sales tax is off', async () => {
|
|
|
const t = makeCtx({
|
|
const t = makeCtx({
|
|
|
answer: (call) => {
|
|
answer: (call) => {
|