Skip to content

Commit

Permalink
feat(package): Check if login is registered for event
Browse files Browse the repository at this point in the history
Closes #35
  • Loading branch information
indcoder committed Jun 15, 2017
1 parent 70d4145 commit f68ec02
Show file tree
Hide file tree
Showing 4 changed files with 189 additions and 126 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
"description": "Module to return the check-in status for a registrants of an Eventbrite event",
"main": "src/index.js",
"scripts": {
"test": "snyk test && mocha --reporter spec *test*/*",
"test": "mocha --reporter spec *test*/*",
"cover": "istanbul cover node_modules/mocha/bin/_mocha -- -R spec tests/*",
"semantic-release": "semantic-release pre && npm publish && semantic-release post",
"commitmsg": "validate-commit-msg"
Expand Down
28 changes: 28 additions & 0 deletions src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -58,8 +58,36 @@ function getAttendeesForEvent(accessToken, eventID, flag) {
throw new Error(err);
});

};

function hasRegisteredForEvent(accessToken, eventID, attendeeID) {
return IPromise
.try(() =>{
const options = {
uri: `https://www.eventbriteapi.com/v3/events/${eventID}/attendees/${attendeeID}`,
qs: {
token: accessToken, // -> uri + '?access_token=xxxxx%20xxxxx'
},
json: true,
};
if(arguments.length < 3 || (typeof accessToken === 'undefined') || (eventID === 'undefined') || (attendeeID === 'undefined')) {
throw new Error('INCORRECT_ARGUMENTS');
}
return rp(options);
})
.then(body =>{
if(body.id === attendeeID)
{return true;}
return false;

})
.catch(error => {
console.error(`Error thrown during invocation ${error}`);
throw error;
});
}

module.exports = {
getAttendeesForEvent,
hasRegisteredForEvent,
};
12 changes: 12 additions & 0 deletions tests/onlineTest.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,17 @@
const eventbriteCheckinsOnline = require('../src/index.js');
/*
eventbriteCheckinsOnline.getAttendeesForEvent('<EVENTBRITE TOKEN>', '<EVENT ID>')
.then(data => {
console.log(data);
});
*/

eventbriteCheckinsOnline.hasRegisteredForEvent('<EVENTBRITE TOKEN>', '<EVENT ID>', 'ATTENDEE ID')
.then(data => {
console.log(data);
})
.catch(error => {
console.log(error);
})

273 changes: 148 additions & 125 deletions tests/test.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ chai.config.includeStack = true;

chai.should();

describe('Given the eventbriteCheckins module test in offline unit mode', ()=> {
describe('Given the eventbriteCheckins module test in offline unit mode', ()=> {
beforeEach(()=>{
sandbox = sinon.sandbox.create();
apiCall = sandbox.stub();
Expand All @@ -21,179 +21,202 @@ describe('Given the eventbriteCheckins module test in offline unit mode', ()=> {
sandbox.restore();
});

it('should return a function', () => {
(eventbriteCheckins.getAttendeesForEvent).should.be.a('function');
});
describe('getEventAttendees', ()=> {
it('is a function', () => {
(eventbriteCheckins.getAttendeesForEvent).should.be.a('function');
});

it('should return a Promise', () => {
const input = {
'attendees': [],
};
apiCall.resolves(JSON.stringify(input));
const checkinsResult = eventbriteCheckins.getAttendeesForEvent('dummytoken', 'dummyeventid');
checkinsResult.then.should.be.a('function');
checkinsResult.catch.should.be.a('function');
});
it('should return a Promise', () => {
const input = {
'attendees': [],
};
apiCall.resolves(input);
const checkinsResult = eventbriteCheckins.getAttendeesForEvent('dummytoken', 'dummyeventid');
checkinsResult.then.should.be.a('function');
checkinsResult.catch.should.be.a('function');
});

it('should throw a network error if a connection cannot be made to Eventbrite API endpoint', ()=>{
const connectError = new Error('getaddrinfo ENOTFOUND');
apiCall.rejects(connectError);
return eventbriteCheckins
.getAttendeesForEvent('testtoken', 'testid')
.should.eventually.be.rejectedWith('getaddrinfo ENOTFOUND');
});
it('should throw a network error if a connection cannot be made to Eventbrite API endpoint', ()=>{
const connectError = new Error('getaddrinfo ENOTFOUND');
apiCall.rejects(connectError);
return eventbriteCheckins
.getAttendeesForEvent('testtoken', 'testid')
.should.eventually.be.rejectedWith('getaddrinfo ENOTFOUND');
});

it('should throw an authentication error if incorrect token is sent in api url', () => {
const authError = new Error('INVALID_AUTH');
apiCall.rejects(authError);
return eventbriteCheckins
.getAttendeesForEvent('dummy_access_token', 'dummy_event_id')
.should.eventually.be.rejectedWith('INVALID_AUTH');
});
it('should throw an authentication error if incorrect token is sent in api url', () => {
const authError = new Error('INVALID_AUTH');
apiCall.rejects(authError);
return eventbriteCheckins
.getAttendeesForEvent('dummy_access_token', 'dummy_event_id')
.should.eventually.be.rejectedWith('INVALID_AUTH');
});

it('should throw the error if EB API returns an error on processing the request', ()=> {
const argumentError = new Error('ARGUMENTS_ERROR');
apiCall.rejects(argumentError);
return eventbriteCheckins
.getAttendeesForEvent('dummy_access_token', 'dummy_event_id')
.should.eventually.be.rejectedWith('ARGUMENTS_ERROR');
});
it('should throw the error if EB API returns an error on processing the request', ()=> {
const argumentError = new Error('ARGUMENTS_ERROR');
apiCall.rejects(argumentError);
return eventbriteCheckins
.getAttendeesForEvent('dummy_access_token', 'dummy_event_id')
.should.eventually.be.rejectedWith('ARGUMENTS_ERROR');
});

it('should return an empty list when no attendees has checked into the event', () => {
const input = {
'attendees': [],
};
apiCall.resolves(input);
return eventbriteCheckins.getAttendeesForEvent('dummy_accesss_token', 'dummy_event_id').should.eventually.be.eql([]);
it('should return an empty list when no attendees has checked into the event', () => {
const input = {
'attendees': [],
};
apiCall.resolves(input);
return eventbriteCheckins.getAttendeesForEvent('dummy_accesss_token', 'dummy_event_id').should.eventually.be.eql([]);

});
});

it('should return the list of checkedin attendees', ()=> {
it('should return the list of checkedin attendees', ()=> {

/*
The input has three dummy attendees in which the first and
last attendee have been marked checked in while the second has not.
*/
const input = { 'attendees':
[
/*
The input has three dummy attendees in which the first and
last attendee have been marked checked in while the second has not.
*/
const input = { 'attendees':
[

{ 'profile': {'first_name': 'Attendee', 'last_name': 'First', 'addresses':
{'home': {'city': 'Mumbai', 'country': 'IN', 'region': 'Maharashtra', 'postal_code': '400000',
'address_1': 'Lala Land', 'address_2': 'Moonlight'},
}, 'cell_phone': '9920220856',
{ 'profile': {'first_name': 'Attendee', 'last_name': 'First', 'addresses':
{'home': {'city': 'Mumbai', 'country': 'IN', 'region': 'Maharashtra', 'postal_code': '400000',
'address_1': 'Lala Land', 'address_2': 'Moonlight'},
}, 'cell_phone': '9920220856',
'email': 'attendee1@mtp.mtp', 'name': 'Attendee First'}, 'barcodes': [{'status': 'used',
'changed': '2017-02-28T13:38:14Z', 'created': '2017-02-18T13:15:47Z',
'checkin_type': 2, 'checkin_method': 'search'}],
'changed': '2017-02-28T13:38:14Z', 'created': '2017-02-18T13:15:47Z',
'checkin_type': 2, 'checkin_method': 'search'}],
'checked_in': true, 'cancelled': false, 'refunded': false,
'status': 'Checked In', 'id': 1001},

{ 'profile': {'first_name': 'Attendee', 'last_name': 'Second', 'addresses':
{'home': {'city': 'Mumbai', 'country': 'IN', 'region': 'Maharashtra', 'postal_code': '400000',
'address_1': 'Lala Land', 'address_2': 'Moonlight'},
}, 'cell_phone': '9920220856',
{ 'profile': {'first_name': 'Attendee', 'last_name': 'Second', 'addresses':
{'home': {'city': 'Mumbai', 'country': 'IN', 'region': 'Maharashtra', 'postal_code': '400000',
'address_1': 'Lala Land', 'address_2': 'Moonlight'},
}, 'cell_phone': '9920220856',
'email': 'attendee2@mtp.mtp', 'name': 'Attendee Second'}, 'barcodes': [{'status': 'used',
'changed': '2017-02-28T13:38:14Z', 'created': '2017-02-18T13:15:47Z',
'checkin_type': 2, 'checkin_method': 'search'}],
'changed': '2017-02-28T13:38:14Z', 'created': '2017-02-18T13:15:47Z',
'checkin_type': 2, 'checkin_method': 'search'}],
'checked_in': false, 'cancelled': false, 'refunded': false,
'status': 'Checked In', 'id': 1002},

{ 'profile': {'first_name': 'Attendee', 'last_name': 'Third', 'addresses':
{'home': {'city': 'Mumbai', 'country': 'IN', 'region': 'Maharashtra', 'postal_code': '400000',
'address_1': 'Lala Land', 'address_2': 'Moonlight'},
}, 'cell_phone': '9920220856',
{ 'profile': {'first_name': 'Attendee', 'last_name': 'Third', 'addresses':
{'home': {'city': 'Mumbai', 'country': 'IN', 'region': 'Maharashtra', 'postal_code': '400000',
'address_1': 'Lala Land', 'address_2': 'Moonlight'},
}, 'cell_phone': '9920220856',
'email': 'attendee3@mtp.mtp', 'name': 'Attendee Third'}, 'barcodes': [{'status': 'used',
'changed': '2017-02-28T13:38:14Z', 'created': '2017-02-18T13:15:47Z',
'checkin_type': 2, 'checkin_method': 'search'}],
'changed': '2017-02-28T13:38:14Z', 'created': '2017-02-18T13:15:47Z',
'checkin_type': 2, 'checkin_method': 'search'}],
'checked_in': true, 'cancelled': false, 'refunded': false,
'status': 'Checked In', 'id': 1003},

]};
]};

const result = [{ name: 'Attendee First',
email: 'attendee1@mtp.mtp',
evenbriteID: 1001 },
const result = [{ name: 'Attendee First',
email: 'attendee1@mtp.mtp',
evenbriteID: 1001 },

{ name: 'Attendee Third',
email: 'attendee3@mtp.mtp',
evenbriteID: 1003 }];
{ name: 'Attendee Third',
email: 'attendee3@mtp.mtp',
evenbriteID: 1003 }];

apiCall.resolves(input);
apiCall.resolves(input);

return eventbriteCheckins
.getAttendeesForEvent('dummyaccesstoken', 'dummyeventid', 'checkedin')
.should.eventually.eql(result);
/*
eventbriteCheckins.getAttendeesForEvent('dummyaccesstoken', 'dummyeventid')
.then((obj) =>{
console.log(obj);
return eventbriteCheckins
.getAttendeesForEvent('dummyaccesstoken', 'dummyeventid', 'checkedin')
.should.eventually.eql(result);

})
.then(done,done);
*/
});
/*
eventbriteCheckins.getAttendeesForEvent('dummyaccesstoken', 'dummyeventid')
.then((obj) =>{
console.log(obj);
it('should return the list of noshow registerants if flag is noshow', () => {
const input = { 'attendees':
[
})
.then(done,done);
*/
});

it('should return the list of noshow registerants if flag is noshow', () => {
const input = { 'attendees':
[

{ 'profile': {'first_name': 'Attendee', 'last_name': 'First', 'addresses':
{'home': {'city': 'Mumbai', 'country': 'IN', 'region': 'Maharashtra', 'postal_code': '400000',
'address_1': 'Lala Land', 'address_2': 'Moonlight'},
}, 'cell_phone': '9920220856',
{ 'profile': {'first_name': 'Attendee', 'last_name': 'First', 'addresses':
{'home': {'city': 'Mumbai', 'country': 'IN', 'region': 'Maharashtra', 'postal_code': '400000',
'address_1': 'Lala Land', 'address_2': 'Moonlight'},
}, 'cell_phone': '9920220856',
'email': 'attendee1@mtp.mtp', 'name': 'Attendee First'}, 'barcodes': [{'status': 'used',
'changed': '2017-02-28T13:38:14Z', 'created': '2017-02-18T13:15:47Z',
'checkin_type': 2, 'checkin_method': 'search'}],
'changed': '2017-02-28T13:38:14Z', 'created': '2017-02-18T13:15:47Z',
'checkin_type': 2, 'checkin_method': 'search'}],
'checked_in': true, 'cancelled': false, 'refunded': false,
'status': 'Checked In', 'id': 1001},

{ 'profile': {'first_name': 'Attendee', 'last_name': 'Second', 'addresses':
{'home': {'city': 'Mumbai', 'country': 'IN', 'region': 'Maharashtra', 'postal_code': '400000',
'address_1': 'Lala Land', 'address_2': 'Moonlight'},
}, 'cell_phone': '9920220856',
{ 'profile': {'first_name': 'Attendee', 'last_name': 'Second', 'addresses':
{'home': {'city': 'Mumbai', 'country': 'IN', 'region': 'Maharashtra', 'postal_code': '400000',
'address_1': 'Lala Land', 'address_2': 'Moonlight'},
}, 'cell_phone': '9920220856',
'email': 'attendee2@mtp.mtp', 'name': 'Attendee Second'}, 'barcodes': [{'status': 'used',
'changed': '2017-02-28T13:38:14Z', 'created': '2017-02-18T13:15:47Z',
'checkin_type': 2, 'checkin_method': 'search'}],
'changed': '2017-02-28T13:38:14Z', 'created': '2017-02-18T13:15:47Z',
'checkin_type': 2, 'checkin_method': 'search'}],
'checked_in': false, 'cancelled': false, 'refunded': false,
'status': 'Checked In', 'id': 1002},

{ 'profile': {'first_name': 'Attendee', 'last_name': 'Third', 'addresses':
{'home': {'city': 'Mumbai', 'country': 'IN', 'region': 'Maharashtra', 'postal_code': '400000',
'address_1': 'Lala Land', 'address_2': 'Moonlight'},
}, 'cell_phone': '9920220856',
{ 'profile': {'first_name': 'Attendee', 'last_name': 'Third', 'addresses':
{'home': {'city': 'Mumbai', 'country': 'IN', 'region': 'Maharashtra', 'postal_code': '400000',
'address_1': 'Lala Land', 'address_2': 'Moonlight'},
}, 'cell_phone': '9920220856',
'email': 'attendee3@mtp.mtp', 'name': 'Attendee Third'}, 'barcodes': [{'status': 'used',
'changed': '2017-02-28T13:38:14Z', 'created': '2017-02-18T13:15:47Z',
'checkin_type': 2, 'checkin_method': 'search'}],
'changed': '2017-02-28T13:38:14Z', 'created': '2017-02-18T13:15:47Z',
'checkin_type': 2, 'checkin_method': 'search'}],
'checked_in': true, 'cancelled': false, 'refunded': false,
'status': 'Checked In', 'id': 1003},

]};
]};

const result = [{ name: 'Attendee Second',
email: 'attendee2@mtp.mtp',
evenbriteID: 1002 },
];
const result = [{ name: 'Attendee Second',
email: 'attendee2@mtp.mtp',
evenbriteID: 1002 },
];

apiCall.resolves(input);
apiCall.resolves(input);

return eventbriteCheckins
.getAttendeesForEvent('dummyaccesstoken', 'dummyeventid', 'noshow')
.should.eventually.eql(result);
});
return eventbriteCheckins
.getAttendeesForEvent('dummyaccesstoken', 'dummyeventid', 'noshow')
.should.eventually.eql(result);
});

it('should throw an error if EB module is invoked with incorrect number of arguments', ()=> {
it('should throw an error if EB module is invoked with incorrect number of arguments', ()=> {

return eventbriteCheckins
.getAttendeesForEvent('dummy_access_token')
.should.eventually.be.rejectedWith('INCORRECT_ARGUMENT');
});
return eventbriteCheckins
.getAttendeesForEvent('dummy_access_token')
.should.eventually.be.rejectedWith('INCORRECT_ARGUMENT');
});

it('should throw an error if EB module is invoked with a wrong flag', ()=> {
it('should throw an error if EB module is invoked with a wrong flag', ()=> {

return eventbriteCheckins
.getAttendeesForEvent('dummy_access_token', 'dummy_event_token', 'random')
.should.eventually.be.rejectedWith('INCORRECT_FLAG');
});

return eventbriteCheckins
.getAttendeesForEvent('dummy_access_token', 'dummy_event_token', 'random')
.should.eventually.be.rejectedWith('INCORRECT_FLAG');
});

describe('hasRegisteredForEvent' , ()=>{
it('is a function', () => {
(eventbriteCheckins.hasRegisteredForEvent).should.be.a('function');
});

it('should return a Promise', () => {
const input = {
'attendees': [],
};
apiCall.resolves(input);
const checkinsResult = eventbriteCheckins.hasRegisteredForEvent('dummytoken', 'dummyeventid','dummyattendeeid');
checkinsResult.then.should.be.a('function');
checkinsResult.catch.should.be.a('function');
});



})

});

/*
Expand Down

0 comments on commit f68ec02

Please sign in to comment.