Skip to content

Commit

Permalink
Fix unit tests
Browse files Browse the repository at this point in the history
  • Loading branch information
ghareeb-falazi committed Nov 24, 2024
1 parent f8feac8 commit 20fac7f
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 8 deletions.
1 change: 1 addition & 0 deletions lib/basic-flight-booking-manager/booking-list.js
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ class BookingList extends StateList {
.update(clientId)
.digest('hex');
let key = Booking.makeKey([clientId, flightId]);

if (this.cache.has(key)) {
return this.cache.get(key);
}
Expand Down
20 changes: 14 additions & 6 deletions lib/basic-flight-booking-manager/client-balance-list.js
Original file line number Diff line number Diff line change
Expand Up @@ -44,20 +44,28 @@ class ClientBalanceList extends StateList {
* @returns {Promise<ClientBalance>}
*/
async getClientBalance(client) {
client = crypto.createHash('sha256')
const clientHash = crypto.createHash('sha256')
.update(client)
.digest('hex');

console.log("client=" + client);
console.log("client=" + clientHash);

if (this.cache.has(client)) {
return this.cache.get(client);
if (this.cache.has(clientHash)) {
console.log("getting client balance from cache");
return this.cache.get(clientHash);
}

let key = ClientBalance.makeKey([client]);
let key = ClientBalance.makeKey([clientHash]);
let result = await this.getState(key);

return result ? ClientBalance.fromBuffer(result) : ClientBalance.createInstance(client, "2000");
if (!result) {
result = ClientBalance.createInstance(client, 2000);
this.cache.set(result.getClient(), result);
} else {
result = ClientBalance.fromBuffer(result);
}

return result;
}

/**
Expand Down
1 change: 0 additions & 1 deletion lib/basic-flight-booking-manager/flight-list.js
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,6 @@ class FlightList extends StateList {

let key = Flight.makeKey([id]);
let result = await this.getState(key);
console.debug("get Flight result = " + result ? Flight.fromBuffer(result) : "null");

return result ? Flight.fromBuffer(result) : null;
}
Expand Down
2 changes: 1 addition & 1 deletion test/basic-flight-booking-manager.test.ts.js
Original file line number Diff line number Diff line change
Expand Up @@ -146,7 +146,7 @@ describe('Basic Flights Manager Basic Tests', () => {
let isSeat22Available = await man.isSeatAvailable(context, 'A', 22);
expect(isSeat22Available).to.be.false;
let balance = await man.queryClientBalance(context);
expect(balance).to.be.equal(2000 - 1000);
expect(balance).to.be.equal(2000 + 2000 - 1000);
let hasRes = await man.hasReservation(context, 'A');
expect(hasRes).to.be.true;
let isSeatBookedByClient = await man.isSeatBookedByClient(context, 'A', 22);
Expand Down

0 comments on commit 20fac7f

Please sign in to comment.