Skip to content

Commit

Permalink
AUT-2602: Introduce new function for a timestamp n seconds from now
Browse files Browse the repository at this point in the history
The backend returns a time to live for a lock in seconds, therefore this introduces a helper method for this.
  • Loading branch information
BeckaL committed Apr 8, 2024
1 parent 29b2527 commit 2c0d7e5
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 0 deletions.
4 changes: 4 additions & 0 deletions src/utils/lock-helper.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,10 @@ export function timestampNMinutesFromNow(numberOfMinutes: number) {
return new Date(Date.now() + numberOfMinutes * 60000).toUTCString();
}

export function timestampNSecondsFromNow(numberOfSeconds: number) {
return new Date(Date.now() + numberOfSeconds * 1000).toUTCString();
}

export function isLocked(maybeLockTimestamp?: string) {
return (
maybeLockTimestamp &&
Expand Down
22 changes: 22 additions & 0 deletions test/unit/utils/lock-helper.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import { describe } from "mocha";
import {
isLocked,
timestampNMinutesFromNow,
timestampNSecondsFromNow,
} from "../../../src/utils/lock-helper";
import sinon from "sinon";
describe("lockout-helper", () => {
Expand Down Expand Up @@ -40,6 +41,27 @@ describe("lockout-helper", () => {
});
});

describe("timestampNSecondsFromNow", () => {
it("should return the correct timestamp from the current datetime", () => {
const TEST_SCENARIO_PARAMS = [
{
numberOfSeconds: 60,
expectedTimestamp: "Thu, 01 Feb 2024 00:01:00 GMT",
},
{
numberOfSeconds: 1,
expectedTimestamp: "Thu, 01 Feb 2024 00:00:01 GMT",
},
];

TEST_SCENARIO_PARAMS.forEach((params) => {
expect(timestampNSecondsFromNow(params.numberOfSeconds)).to.eq(
params.expectedTimestamp
);
});
});
});

describe("checkIfLocked", () => {
it("should correctly determine if a user is locked", () => {
const TEST_SCENARIO_PARAMS = [
Expand Down

0 comments on commit 2c0d7e5

Please sign in to comment.