Skip to content

Commit

Permalink
Merge pull request #130 from starkbank/feature/logs
Browse files Browse the repository at this point in the history
Add logs
  • Loading branch information
luistarkbank authored Jul 16, 2024
2 parents 46764f7 + 00f7b30 commit ad7e038
Show file tree
Hide file tree
Showing 7 changed files with 79 additions and 7 deletions.
5 changes: 2 additions & 3 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -58,13 +58,12 @@ exports.webhook = require('./sdk/webhook');
exports.workspace = require('./sdk/workspace');
exports.event = require('./sdk/event');
exports.institution = require('./sdk/institution')
exports.merchantSession = require('./sdk/merchantSession');
exports.merchantPurchase = require('./sdk/merchantPurchase');
exports.key = require('./sdk/key.js');
exports.error = require('./sdk/error.js');
exports.organization = require('./sdk/user/organization.js')
exports.request = require('./sdk/request/request.js')
exports.merchantSession = require('./sdk/merchantSession/merchantSession.js')
exports.merchantSessionPurchase = require('./sdk/merchantSession/purchase.js')
exports.merchantPurchase = require('./sdk/merchantPurchase/merchantPurchase.js')


// Classes
Expand Down
6 changes: 5 additions & 1 deletion sdk/merchantPurchase/index.js
Original file line number Diff line number Diff line change
@@ -1 +1,5 @@
const merchantPurchase = require('./merchantPurchase.js')
const merchantPurchase = require('./merchantPurchase.js')
exports.log = require('./log');
exports.MerchantPurchase = merchantPurchase.MerchantPurchase;
exports.query = merchantPurchase.query;
exports.get = merchantPurchase.get;
4 changes: 4 additions & 0 deletions sdk/merchantPurchase/log/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
const log = require('./log.js');

exports.get = log.get;
exports.query = log.query;
34 changes: 34 additions & 0 deletions sdk/merchantPurchase/log/log.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
const rest = require('../../utils/rest.js');
const check = require('starkcore').check;
const Resource = require('../../utils/resource.js').Resource

class Log extends Resource {

/**
* Check out our API Documentation at https://starkbank.com/docs/api#merchant-purchase
*/

constructor({ created, type, errors, merchantPurchase, id }) {
super(id);
this.created = check.datetime(created);
this.type = type;
this.errors = errors;
this.merchantPurchase = merchantPurchase;
}
}

exports.Log = Log;
let resource = {'class': exports.Log, 'name': 'MerchantPurchaseLog'};

exports.get = async function (id, {user} = {}) {
return rest.getId(resource, id, user);
};

exports.query = async function ({ limit, after, before, user} = {}) {
let query = {
limit: limit,
after: after,
before: before
};
return rest.getList(resource, query, user);
};
3 changes: 3 additions & 0 deletions sdk/merchantSession/index.js
Original file line number Diff line number Diff line change
@@ -1 +1,4 @@
const merchantSession = require('./merchantSession.js');
exports.MerchantSession = merchantSession.MerchantSession;
exports.create = merchantSession.create;
exports.purchase = merchantSession.purchase;
9 changes: 6 additions & 3 deletions tests/testMerchantPurchase.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,10 @@ describe('MerchantSessionQuery', function(){
describe('MerchantSessionGet', function(){
this.timeout(10000);
it('test_success', async () => {
let merchantPurchase = await starkbank.merchantPurchase.get(5019538395496448);
assert(typeof merchantPurchase.id == 'string');
let merchantPurchases = await starkbank.merchantPurchase.query({limit: 3});
for await (let purchase of merchantPurchases) {
let merchantPurchase = await starkbank.merchantPurchase.get(purchase.id);
assert(typeof merchantPurchase.id == 'string');
}
});
});
});
25 changes: 25 additions & 0 deletions tests/testMerchantPurchaseLog.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
const assert = require('assert');
const starkbank = require('../index.js');

starkbank.user = require('./utils/user').exampleProject;

describe('MerchantSessionQueryLog', function(){
this.timeout(10000);
it('test_success', async () => {
let logs = await starkbank.merchantPurchase.log.query({limit: 3});
for await (let log of logs) {
assert(typeof log.id == 'string');
}
});
});

describe('MerchantSessionGetLog', function(){
this.timeout(10000);
it('test_success', async () => {
let logs = await starkbank.merchantPurchase.log.query({limit: 1});
for await (let log of logs) {
log = await starkbank.merchantPurchase.log.get(log.id);
assert(typeof log.id == 'string');
}
});
});

0 comments on commit ad7e038

Please sign in to comment.