mobile-session-promise
Version:
The modules creates a promise that resolves an existing or creates a brand new session
69 lines (61 loc) • 2.55 kB
JavaScript
;
/*
* The unit test suite for the mobileSession/index.js module
* Before you run it with 'npm test' command please make sure that the
* Local DynamoDB is up and running on port 8090:
* java -Djava.library.path=./DynamoDBLocal_lib -jar DynamoDBLocal.jar -sharedDb -port 8090
* For more details about local Dynamo DB please refer to the link below:
* http://docs.aws.amazon.com/amazondynamodb/latest/developerguide/DynamoDBLocal.html
*
* Copyright(c) Nordstrom,Inc. All Rights reserved. This software is the confidential and
* proprietary information of Nordstrom, Inc. ("Confidential Information"). You shall not disclose
* such Confidential Information and shall use it only in accordance with the terms of the license
* agreement you entered into with Nordstrom, Inc.
*/
const chai = require('chai');
const mockery = require('mockery');
const assert = chai.assert;
chai.should();
const uuid = require('uuid');
mockery.enable({
warnOnReplace: false,
warnOnUnregistered: false,
useCleanCache: true
});
const mobileSessionPromiseFactory = require('..');
describe('When no previous event with given user_id is found (USER_ID_NOT_FOUND)', () => {
it('it should generate a brand new session', done => {
const event_id = uuid.v4();
const domain_userid = uuid.v4();
const collector_tstamp = Date.now() - 1000;
const sent_tstamp = Date.now() - 2000;
const created_tstamp = Date.now() - 3000;
const promise = mobileSessionPromiseFactory(
event_id,
domain_userid,
collector_tstamp,
created_tstamp,
sent_tstamp
);
console.log("Promise",promise);
promise.then(sessionInfo => {
assert(sessionInfo.session_id, 'Session id must be present');
sessionInfo.session_index.should.equal(0);
sessionInfo.user_id.should.equal(domain_userid);
sessionInfo.previous_session_id.should.equal('ZZZZZZ');
sessionInfo.orig_event_id.should.equal(event_id); // orig event id should equal to the supplied event id
sessionInfo.first_event_id.should.equal(event_id);
done();
}
).catch(sessionInfo => {
assert(sessionInfo.session_id, 'Error Session id must be present');
sessionInfo.session_index.should.equal(0);
sessionInfo.user_id.should.equal(domain_userid);
sessionInfo.previous_session_id.should.equal('ZZZZZZ');
sessionInfo.orig_event_id.should.equal(event_id); // orig event id should equal to the supplied event id
sessionInfo.first_event_id.should.equal(event_id);
done();
})
;
});
});