-
Notifications
You must be signed in to change notification settings - Fork 13
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Implement support for async activities export (#62)
- Loading branch information
Thomas Carney
authored
Jul 19, 2021
1 parent
fa1fc3e
commit eb89928
Showing
5 changed files
with
86 additions
and
1 deletion.
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
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,13 @@ | ||
'use strict'; | ||
|
||
const Resource = require('../resource.js'); | ||
|
||
class ActivitiesExport extends Resource { | ||
static get path () { | ||
return '/v1/activities_export/{activitiesExportUuid}'; | ||
} | ||
} | ||
|
||
ActivitiesExport.create = Resource._method('POST', '/v1/activities_export'); | ||
|
||
module.exports = ActivitiesExport; |
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 |
---|---|---|
@@ -0,0 +1,68 @@ | ||
'use strict'; | ||
|
||
const ChartMogul = require('../../../lib/chartmogul'); | ||
const config = new ChartMogul.Config('token', 'secret'); | ||
const expect = require('chai').expect; | ||
const nock = require('nock'); | ||
const ActivitiesExport = ChartMogul.Metrics.ActivitiesExport; | ||
|
||
describe('ActivitiesExport', () => { | ||
it('should create an activities export', () => { | ||
const pendingExport = { | ||
id: '7f554dba-4a41-4cb2-9790-2045e4c3a5b1', | ||
status: 'pending', | ||
file_url: null, | ||
params: { | ||
kind: 'activities', | ||
params: { | ||
activity_type: 'contraction', | ||
start_date: '2020-01-01', | ||
end_date: '2020-12-31' | ||
} | ||
}, | ||
expires_at: null, | ||
created_at: '2021-07-12T14:46:56+00:00' | ||
}; | ||
|
||
const query = { | ||
'start-date': '2020-01-01', | ||
'end-date': '2020-12-31', | ||
type: 'contraction' | ||
}; | ||
|
||
nock(config.API_BASE) | ||
.post('/v1/activities_export') | ||
.reply(200, pendingExport); | ||
|
||
return ActivitiesExport.create(config, query) | ||
.then(res => { | ||
expect(res).to.be.deep.equal(pendingExport); | ||
}); | ||
}); | ||
|
||
it('should retrieve a successful activities export after a period of time', () => { | ||
const succeededExport = { | ||
id: '7f554dba-4a41-4cb2-9790-2045e4c3a5b1', | ||
status: 'succeeded', | ||
file_url: 'https://chartmogul-customer-export.s3.eu-west-1.amazonaws.com/activities-acme-corp-91e1ca88-d747-4e25-83d9-2b752033bdba.zip', | ||
params: { | ||
kind: 'activities', | ||
params: { | ||
activity_type: 'contraction', | ||
start_date: '2020-01-01', | ||
end_date: '2020-12-31' | ||
} | ||
}, | ||
expires_at: '2021-07-19T14:46:58+00:00', | ||
created_at: '2021-07-12T14:46:56+00:00' | ||
}; | ||
nock(config.API_BASE) | ||
.get('/v1/activities_export/7f554dba-4a41-4cb2-9790-2045e4c3a5b1') | ||
.reply(200, succeededExport); | ||
|
||
return ActivitiesExport.retrieve(config, '7f554dba-4a41-4cb2-9790-2045e4c3a5b1') | ||
.then(res => { | ||
expect(res).to.be.deep.equal(succeededExport); | ||
}); | ||
}); | ||
}); |