-
Notifications
You must be signed in to change notification settings - Fork 36
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
ccb00b2
commit da639cc
Showing
7 changed files
with
129 additions
and
11 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 |
---|---|---|
|
@@ -373,6 +373,29 @@ api.getCustomersByEmail("[email protected]"); | |
|
||
- **email**: String (required) | ||
|
||
### api.getAttributes(id, id_type) | ||
|
||
Returns a list of attributes for a customer profile. | ||
|
||
```javascript | ||
api.getAttributes("1", "id"); | ||
``` | ||
|
||
OR | ||
|
||
```javascript | ||
const { IdentifierType } = require("customerio-node"); | ||
|
||
api.getAttributes("1", IdentifierType.ID); | ||
``` | ||
|
||
[You can learn more about the available recipient fields here](https://customer.io/docs/api/#operation/getPersonAttributes). | ||
|
||
#### Options | ||
|
||
- **id**: Customer identifier, String or number (required) | ||
- **id_type**: One of the ID types - "id" / "email" / "cio_id" (default is "id") | ||
|
||
### api.listExports() | ||
|
||
Return a list of your exports. Exports are point-in-time people or campaign metrics. | ||
|
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,4 +1,5 @@ | ||
export * from './lib/track'; | ||
export * from './lib/api'; | ||
export * from './lib/regions'; | ||
export { IdentifierType } from './lib/types'; | ||
export { CustomerIORequestError } from './lib/utils'; |
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
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 |
---|---|---|
|
@@ -2,7 +2,7 @@ import avaTest, { TestFn } from 'ava'; | |
import sinon, { SinonStub } from 'sinon'; | ||
import { APIClient, DeliveryExportMetric, DeliveryExportRequestOptions, SendEmailRequest } from '../lib/api'; | ||
import { RegionUS, RegionEU } from '../lib/regions'; | ||
import { Filter } from '../lib/types'; | ||
import { Filter, IdentifierType } from '../lib/types'; | ||
|
||
type TestContext = { client: APIClient }; | ||
|
||
|
@@ -140,28 +140,27 @@ test('#getCustomersByEmail: searching for a customer email (default)', (t) => { | |
const email = '[email protected]'; | ||
t.context.client.getCustomersByEmail(email); | ||
t.truthy((t.context.client.request.get as SinonStub).calledWith(`${RegionUS.apiUrl}/customers?email=${email}`)); | ||
}) | ||
}); | ||
|
||
test('#getCustomersByEmail: should throw error when email is empty', (t) => { | ||
const email = ''; | ||
t.throws(() => t.context.client.getCustomersByEmail(email)); | ||
}) | ||
|
||
}); | ||
|
||
test('#getCustomersByEmail: should throw error when email is null', (t) => { | ||
const email: unknown = null; | ||
t.throws(() => t.context.client.getCustomersByEmail(email as string)); | ||
}) | ||
}); | ||
|
||
test('#getCustomersByEmail: should throw error when email is undefined', (t) => { | ||
const email: unknown = undefined; | ||
t.throws(() => t.context.client.getCustomersByEmail(email as string)); | ||
}) | ||
}); | ||
|
||
test('#getCustomersByEmail: should throw error when email is not a string object', (t) => { | ||
const email: unknown = { "object": "test" }; | ||
const email: unknown = { object: 'test' }; | ||
t.throws(() => t.context.client.getCustomersByEmail(email as string)); | ||
}) | ||
}); | ||
|
||
test('#sendEmail: adding attachments with encoding (default)', (t) => { | ||
sinon.stub(t.context.client.request, 'post'); | ||
|
@@ -387,3 +386,67 @@ test('#createDeliveriesExport: fails without id', (t) => { | |
}); | ||
t.falsy((t.context.client.request.post as SinonStub).calledWith(`${RegionUS.apiUrl}/exports/deliveries`)); | ||
}); | ||
|
||
test('#getAttributes: fails without customerId', (t) => { | ||
sinon.stub(t.context.client.request, 'get'); | ||
t.throws(() => (t.context.client.getAttributes as any)(), { | ||
message: 'customerId is required', | ||
}); | ||
t.falsy( | ||
(t.context.client.request.get as SinonStub).calledWith(`${RegionUS.apiUrl}/customers/1/attributes?id_type=id`), | ||
); | ||
}); | ||
|
||
test('#getAttributes: fails if id_type is not id, cio_id nor email', (t) => { | ||
sinon.stub(t.context.client.request, 'get'); | ||
t.throws(() => (t.context.client.getAttributes as any)(1, 'first_name'), { | ||
message: 'idType must be one of "id", "cio_id", or "email"', | ||
}); | ||
t.falsy( | ||
(t.context.client.request.get as SinonStub).calledWith(`${RegionUS.apiUrl}/customers/1/attributes?id_type=id`), | ||
); | ||
}); | ||
|
||
test('#getAttributes: fails if id_type is null', (t) => { | ||
sinon.stub(t.context.client.request, 'get'); | ||
t.throws(() => (t.context.client.getAttributes as any)(1, null), { | ||
message: 'idType must be one of "id", "cio_id", or "email"', | ||
}); | ||
t.falsy( | ||
(t.context.client.request.get as SinonStub).calledWith(`${RegionUS.apiUrl}/customers/1/attributes?id_type=id`), | ||
); | ||
}); | ||
|
||
test('#getAttributes: success with default type id', (t) => { | ||
sinon.stub(t.context.client.request, 'get'); | ||
t.context.client.getAttributes('1'); | ||
t.truthy( | ||
(t.context.client.request.get as SinonStub).calledWith(`${RegionUS.apiUrl}/customers/1/attributes?id_type=id`), | ||
); | ||
}); | ||
|
||
test('#getAttributes: success with type id', (t) => { | ||
sinon.stub(t.context.client.request, 'get'); | ||
t.context.client.getAttributes('1', IdentifierType.Id); | ||
t.truthy( | ||
(t.context.client.request.get as SinonStub).calledWith(`${RegionUS.apiUrl}/customers/1/attributes?id_type=id`), | ||
); | ||
}); | ||
|
||
test('#getAttributes: success with type cio id', (t) => { | ||
sinon.stub(t.context.client.request, 'get'); | ||
t.context.client.getAttributes('1', IdentifierType.CioId); | ||
t.truthy( | ||
(t.context.client.request.get as SinonStub).calledWith(`${RegionUS.apiUrl}/customers/1/attributes?id_type=cio_id`), | ||
); | ||
}); | ||
|
||
test('#getAttributes: success with type email', (t) => { | ||
sinon.stub(t.context.client.request, 'get'); | ||
t.context.client.getAttributes('[email protected]', IdentifierType.Email); | ||
t.truthy( | ||
(t.context.client.request.get as SinonStub).calledWith( | ||
`${RegionUS.apiUrl}/customers/[email protected]/attributes?id_type=email`, | ||
), | ||
); | ||
}); |
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