-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* feat: add contacts query * feat: add test
- Loading branch information
Showing
3 changed files
with
196 additions
and
0 deletions.
There are no files selected for viewing
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,85 @@ | ||
import { endOfMonth, startOfMonth } from 'date-fns'; | ||
import nock from 'nock'; | ||
import { invariant } from 'ts-invariant'; | ||
import { parseRuntypeValidationError } from '../../../utils'; | ||
import { TripletexContact } from '../contact'; | ||
|
||
const baseUrl = process.env.BASE_URL || 'https://api.tripletex.io/'; | ||
const sessionToken = process.env.SESSION_TOKEN || 'a-session-token'; | ||
|
||
describe('activity class', () => { | ||
let client: TripletexContact; | ||
|
||
beforeEach(() => { | ||
client = new TripletexContact({ baseUrl }, sessionToken); | ||
}); | ||
|
||
it('should list contacts', async () => { | ||
nock('https://api.tripletex.io:443', { encodedQueryParams: true }) | ||
.get('/v2/contact') | ||
.reply(200, { | ||
fullResultSize: 1, | ||
from: 0, | ||
count: 1, | ||
versionDigest: 'Checksum not yet supported for this endpoint', | ||
values: [ | ||
{ | ||
id: 1734852, | ||
version: 1, | ||
url: 'api.tripletex.io/v2/contact/1734852', | ||
firstName: 'Simen A. W. Olsen', | ||
lastName: 'API Testuser', | ||
displayName: 'Simen A. W. Olsen API Testuser', | ||
email: '[email protected]', | ||
phoneNumberMobileCountry: { | ||
id: 161, | ||
url: 'api.tripletex.io/v2/country/161', | ||
}, | ||
phoneNumberMobile: '', | ||
phoneNumberWork: '', | ||
customer: { | ||
id: 88885, | ||
url: 'api.tripletex.io/v2/customer/88885', | ||
}, | ||
department: { | ||
id: 88885, | ||
url: 'api.tripletex.io/v2/department/88885', | ||
}, | ||
isInactive: false, | ||
}, | ||
], | ||
}); | ||
const entries = await client.list(); | ||
|
||
parseRuntypeValidationError(entries.error); | ||
invariant(entries.success); | ||
expect(entries.body.values).toMatchInlineSnapshot(` | ||
Array [ | ||
Object { | ||
"customer": Object { | ||
"id": 88885, | ||
"url": "api.tripletex.io/v2/customer/88885", | ||
}, | ||
"department": Object { | ||
"id": 88885, | ||
"url": "api.tripletex.io/v2/department/88885", | ||
}, | ||
"displayName": "Simen A. W. Olsen API Testuser", | ||
"email": "[email protected]", | ||
"firstName": "Simen A. W. Olsen", | ||
"id": 1734852, | ||
"isInactive": false, | ||
"lastName": "API Testuser", | ||
"phoneNumberMobile": "", | ||
"phoneNumberMobileCountry": Object { | ||
"id": 161, | ||
"url": "api.tripletex.io/v2/country/161", | ||
}, | ||
"phoneNumberWork": "", | ||
"url": "api.tripletex.io/v2/contact/1734852", | ||
"version": 1, | ||
}, | ||
] | ||
`); | ||
}); | ||
}); |
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,77 @@ | ||
import { DefaultTripletexInputs } from "../../types"; | ||
import { serializeQuery, withRuntype } from "../../utils"; | ||
import { TripletexBase } from "../base"; | ||
import { listContactsResponseRt } from "./models/contact"; | ||
|
||
export interface ListContactsInput extends DefaultTripletexInputs { | ||
/** | ||
* List of IDs | ||
*/ | ||
id?: string[]; | ||
|
||
/** | ||
* Containing | ||
*/ | ||
firstName?: string; | ||
|
||
/** | ||
* Containing | ||
*/ | ||
lastName?: string; | ||
|
||
/** | ||
* Containing | ||
*/ | ||
email?: string; | ||
|
||
/** | ||
* List of IDs | ||
*/ | ||
customerId?: string; | ||
|
||
/** | ||
* List of IDs | ||
*/ | ||
departmentId?: string; | ||
|
||
/** | ||
* From index | ||
*/ | ||
includeContacts?: boolean; | ||
|
||
/** | ||
* List of IDs | ||
*/ | ||
deploymentId?: string[]; | ||
|
||
/** | ||
* Number of elements to return | ||
*/ | ||
count: number; | ||
|
||
/** | ||
* Sorting pattern | ||
*/ | ||
sorting: string; | ||
|
||
/** | ||
* Fields filter pattern | ||
*/ | ||
fields: string; | ||
} | ||
|
||
export class TripletexContact extends TripletexBase { | ||
list(input?: ListContactsInput) { | ||
const call = this.authenticatedCall() // | ||
.args<{ | ||
input?: ListContactsInput; | ||
}>() | ||
.path('/v2/contact') | ||
.query(args => (args.input ? serializeQuery(args.input) : {})) | ||
.method('get') | ||
.parseJson(withRuntype(listContactsResponseRt)) | ||
.build(); | ||
|
||
return this.performRequest(sessionToken => call({ input, sessionToken })); | ||
} | ||
} |
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,34 @@ | ||
import * as rt from 'runtypes'; | ||
import { multipleValuesEnvelope } from '../../../utils'; | ||
|
||
const contactRt = rt.Record({ | ||
id: rt.Number, | ||
version: rt.Number.nullable().optional(), | ||
url: rt.String, | ||
firstName: rt.String, | ||
lastName: rt.String, | ||
displayName: rt.String.nullable().optional(), | ||
email: rt.String.nullable().optional(), | ||
phoneNumberMobileCountry: rt | ||
.Record({ | ||
id: rt.Number, | ||
}) | ||
.nullable() | ||
.optional(), | ||
phoneNumberMobile: rt.String.nullable().optional(), | ||
phoneNumberWork: rt.String.nullable().optional(), | ||
customer: rt.Record({ | ||
id: rt.Number, | ||
url: rt.String, | ||
}), | ||
department: rt.Record({ | ||
id: rt.Number, | ||
url: rt.String, | ||
}), | ||
isInactive: rt.Boolean.nullable().optional(), | ||
}) | ||
|
||
export type Contact = rt.Static<typeof contactRt>; | ||
|
||
|
||
export const listContactsResponseRt = multipleValuesEnvelope(contactRt); |