All files / server/src/features/assignment/utils getTimeNow.ts

85.71% Statements 6/7
75% Branches 6/8
100% Functions 1/1
85.71% Lines 6/7

Press n or j to go to the next uncovered block, b, p or k for the previous block.

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20            54x 1022x 1022x 1022x     1022x         750x    
import dayjs, { Dayjs } from "dayjs";
import { config } from "shared/config";
import { findTestSettings } from "server/test/test-settings/testSettingsRepository";
import { MongoDbError } from "shared/types/api/errors";
import { Result, makeSuccessResult } from "shared/utils/result";
 
export const getTimeNow = async (): Promise<Result<Dayjs, MongoDbError>> => {
  Eif (process.env.SETTINGS !== "production" && config.server().useTestTime) {
    const findTestSettingsResult = await findTestSettings();
    Iif (!findTestSettingsResult.ok) {
      return findTestSettingsResult;
    }
    return makeSuccessResult(
      dayjs(findTestSettingsResult.value.testTime ?? dayjs()),
    );
  }
 
  return makeSuccessResult(dayjs());
};