-
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
changed configuration of variables, removed SendInvoiceToMyCompany
- Loading branch information
Showing
10 changed files
with
176 additions
and
142 deletions.
There are no files selected for viewing
This file was deleted.
Oops, something went wrong.
This file contains 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 |
---|---|---|
@@ -1,32 +1,59 @@ | ||
// MaventaService.system.test.ts | ||
|
||
import { ProcessUtils } from "../ProcessUtils"; | ||
ProcessUtils.initEnvFromDefaultFiles(); | ||
|
||
import { MaventaService } from './MaventaService'; | ||
import { MaventaConfig } from './MaventaConfig'; | ||
import { LogLevel } from "../types/LogLevel"; | ||
import { RequestClientImpl } from "../RequestClientImpl"; | ||
import { HttpService } from "../HttpService"; | ||
import { HgNode } from '../../node/HgNode'; | ||
import { MaventaConfig } from './types/MaventaConfig'; | ||
import { DEFAULT_MAVENTA_BASE_URL_TEST, DEFAULT_MAVENTA_SCOPE } from "./maventa-constants"; | ||
|
||
const MAVENTA_BASE_URL = DEFAULT_MAVENTA_BASE_URL_TEST; | ||
const CLIENT_ID = process.env.CLIENT_ID ?? ''; | ||
const CLIENT_SECRET = process.env.CLIENT_SECRET ?? ''; | ||
const SCOPE = DEFAULT_MAVENTA_SCOPE; | ||
const VENDOR_API_KEY = process.env.VENDOR_API_KEY ?? ''; | ||
const COMPANY_EDI = process.env.COMPANY_EDI ?? ''; | ||
|
||
RequestClientImpl.setLogLevel(LogLevel.NONE); | ||
HttpService.setLogLevel(LogLevel.NONE); | ||
|
||
console.log('MaventaService system tests loaded'); | ||
|
||
(CLIENT_ID && CLIENT_SECRET && VENDOR_API_KEY && COMPANY_EDI ? describe : describe.skip)('system', () => { | ||
|
||
describe('MaventaService', () => { | ||
let service: MaventaService; | ||
let config: MaventaConfig; | ||
|
||
beforeAll(() => { | ||
HgNode.initialize(); | ||
}); | ||
|
||
beforeEach(() => { | ||
config = { | ||
baseUrl: MAVENTA_BASE_URL, | ||
clientId: CLIENT_ID, | ||
clientSecret: CLIENT_SECRET, | ||
scope: SCOPE, | ||
vendorApiKey: VENDOR_API_KEY, | ||
companyEDI: COMPANY_EDI | ||
}; | ||
service = new MaventaService(config); | ||
}); | ||
|
||
describe('#listInvoices', () => { | ||
it('should fetch real invoices from the Maventa API', async () => { | ||
const invoices = await service.listInvoices(); | ||
expect(Array.isArray(invoices)).toBe(true); | ||
expect(invoices.length).toBeGreaterThan(0); | ||
expect(invoices[0]).toHaveProperty('id'); | ||
expect(invoices[0]).toHaveProperty('status'); | ||
}); | ||
}); | ||
}); | ||
|
||
describe('MaventaService System Tests', () => { | ||
|
||
beforeAll(() => { | ||
HgNode.initialize(); | ||
console.log('Running system tests against:', MaventaConfig.baseUrl); | ||
}); | ||
|
||
it('should fetch real invoices from the Maventa API', async () => { | ||
const invoices = await MaventaService.listInvoices(); | ||
console.log('Fetched invoices:', invoices); | ||
|
||
expect(invoices).toBeInstanceOf(Array); | ||
if (invoices.length > 0) { | ||
console.log(`Displaying details of the first invoice:`); | ||
console.log(`Invoice ID: ${invoices[0].id}`); | ||
console.log(`Invoice Status: ${invoices[0].status}`); | ||
console.log(`Invoice Amount: ${invoices[0].sum}`); | ||
|
||
expect(invoices[0]).toHaveProperty('id'); | ||
expect(invoices[0]).toHaveProperty('status'); | ||
expect(invoices[0].id).toBeDefined(); | ||
expect(invoices[0].status).toBeDefined(); | ||
} else { | ||
console.log('No invoices found.'); | ||
} | ||
}); | ||
|
||
}); | ||
}); |
This file contains 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 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,3 @@ | ||
export const DEFAULT_MAVENTA_BASE_URL = 'https://ax.maventa.com'; | ||
export const DEFAULT_MAVENTA_BASE_URL_TEST = 'https://ax-stage.maventa.com'; | ||
export const DEFAULT_MAVENTA_SCOPE = 'eui'; |
This file contains 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 |
---|---|---|
@@ -1,9 +1,7 @@ | ||
interface MaventaAction { | ||
type: string; | ||
channel: string; | ||
message: string | null; | ||
key: string | null; | ||
happened_at: string; | ||
} | ||
|
||
export { MaventaAction } | ||
export interface MaventaAction { | ||
readonly type: string; | ||
readonly channel: string; | ||
readonly message: string | null; | ||
readonly key: string | null; | ||
readonly happened_at: string; | ||
} |
This file contains 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,8 @@ | ||
export interface MaventaConfig { | ||
readonly baseUrl: string; | ||
readonly clientId: string; | ||
readonly clientSecret: string; | ||
readonly scope: string; | ||
readonly vendorApiKey: string; | ||
readonly companyEDI: string; | ||
} |
This file contains 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 |
---|---|---|
@@ -1,9 +1,7 @@ | ||
interface MaventaFile { | ||
id: string; | ||
filename: string; | ||
type: string; | ||
mimetype: string; | ||
href: string; | ||
} | ||
|
||
export { MaventaFile } | ||
export interface MaventaFile { | ||
readonly id: string; | ||
readonly filename: string; | ||
readonly type: string; | ||
readonly mimetype: string; | ||
readonly href: string; | ||
} |
This file contains 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 |
---|---|---|
@@ -1,28 +1,57 @@ | ||
import { MaventaAction } from "./MaventaAction"; | ||
import { MaventaRecipient } from "./MaventaRecipient"; | ||
import { MaventaSender } from "./MaventaSender"; | ||
import { MaventaFile } from "./MaventaFile"; | ||
|
||
export interface MaventaRevisionObject { | ||
readonly [key: string]: unknown; | ||
} | ||
|
||
interface MaventaInvoice { | ||
id: string; | ||
status: string; | ||
reference: string | null; | ||
number: string; | ||
sender: MaventaSender; | ||
recipient: MaventaRecipient; | ||
received_at?: string; | ||
created_at: string; | ||
date: string; | ||
date_due: string; | ||
source_format: string; | ||
sum: number; | ||
sum_tax: number; | ||
currency: string; | ||
destination: string | null; | ||
comment: string | null; | ||
files: Array<File>; | ||
actions: Array<MaventaAction>; | ||
revision: Record<string, unknown>; | ||
export interface MaventaInvoice { | ||
readonly id: string; | ||
readonly status: string; | ||
readonly reference: string | null; | ||
readonly number: string; | ||
readonly sender: MaventaSender; | ||
readonly recipient: MaventaRecipient; | ||
readonly received_at?: string; | ||
readonly created_at: string; | ||
readonly date: string; | ||
readonly date_due: string; | ||
readonly source_format: string; | ||
readonly sum: number; | ||
readonly sum_tax: number; | ||
readonly currency: string; | ||
readonly destination: string | null; | ||
readonly comment: string | null; | ||
readonly files: readonly MaventaFile[]; | ||
readonly actions: readonly MaventaAction[]; | ||
readonly revision: MaventaRevisionObject; | ||
} | ||
|
||
export { MaventaInvoice }; | ||
export function isMaventaInvoice(data: unknown): data is MaventaInvoice { | ||
const record = data as MaventaInvoice; | ||
return record != null && | ||
typeof record === 'object' && | ||
typeof record.id === 'string' && | ||
typeof record.status === 'string' && | ||
(typeof record.reference === 'string' || record.reference === null) && | ||
typeof record.number === 'string' && | ||
typeof record.sender === 'object' && record.sender !== null && | ||
typeof record.recipient === 'object' && record.recipient !== null && | ||
(typeof record.received_at === 'string' || record.received_at === undefined) && | ||
typeof record.created_at === 'string' && | ||
typeof record.date === 'string' && | ||
typeof record.date_due === 'string' && | ||
typeof record.source_format === 'string' && | ||
typeof record.sum === 'number' && | ||
typeof record.sum_tax === 'number' && | ||
typeof record.currency === 'string' && | ||
(typeof record.destination === 'string' || record.destination === null) && | ||
(typeof record.comment === 'string' || record.comment === null) && | ||
Array.isArray(record.files) && | ||
record.files.every(file => typeof file === 'object' && file !== null) && | ||
Array.isArray(record.actions) && | ||
record.actions.every(action => typeof action === 'object' && action !== null) && | ||
typeof record.revision === 'object' && record.revision !== null; | ||
} |
This file contains 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 |
---|---|---|
@@ -1,9 +1,5 @@ | ||
interface MaventaRecipient { | ||
eia: string | null; | ||
bid: string | null; | ||
name: string; | ||
country: string; | ||
operator: string | null; | ||
} | ||
|
||
export { MaventaRecipient } | ||
export interface MaventaRecipient { | ||
readonly name: string; | ||
readonly country: string; | ||
readonly operator: string | null; | ||
} |
This file contains 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 |
---|---|---|
@@ -1,8 +1,6 @@ | ||
interface MaventaSender { | ||
eia: string | null; | ||
bid: string | null; | ||
name: string; | ||
country: string; | ||
} | ||
|
||
export { MaventaSender } | ||
export interface MaventaSender { | ||
readonly eia: string | null; | ||
readonly bid: string | null; | ||
readonly name: string; | ||
readonly country: string; | ||
} |