• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

GEWIS / sudosos-backend / 25753937432

12 May 2026 09:17AM UTC coverage: 88.117% (-1.0%) from 89.089%
25753937432

push

github

web-flow
chore(deps): fix missing dependencies for running docs:dev (#911)

3925 of 4574 branches covered (85.81%)

Branch coverage included in aggregate %.

20093 of 22683 relevant lines covered (88.58%)

1125.83 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

83.78
/src/controller/request/validators/banner-request-spec.ts
1
/**
1✔
2
 *  SudoSOS back-end API service.
3
 *  Copyright (C) 2026 Study association GEWIS
4
 *
5
 *  This program is free software: you can redistribute it and/or modify
6
 *  it under the terms of the GNU Affero General Public License as published
7
 *  by the Free Software Foundation, either version 3 of the License, or
8
 *  (at your option) any later version.
9
 *
10
 *  This program is distributed in the hope that it will be useful,
11
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
12
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13
 *  GNU Affero General Public License for more details.
14
 *
15
 *  You should have received a copy of the GNU Affero General Public License
16
 *  along with this program.  If not, see <https://www.gnu.org/licenses/>.
17
 *
18
 *  @license
19
 */
1✔
20

21
/**
1✔
22
 * This is the module page of the banner-request-spec.
23
 *
24
 * @module internal/spec/banner-request-spec
25
 */
1✔
26

27
import {
28
  Specification, toFail, toPass, ValidationError,
29
} from '../../../helpers/specification-validation';
30
import BannerRequest from '../banner-request';
31
import stringSpec from './string-spec';
32
import durationSpec from './duration-spec';
33

34
/**
1✔
35
 * Validates that the duration is a positive integer.
36
 */
1✔
37
const validDuration = (duration: number) => {
1✔
38
  if (duration <= 0 || !Number.isInteger(duration)) {
3!
39
    return toFail(new ValidationError('Duration must be a positive integer.'));
×
40
  }
×
41
  return toPass(duration);
3✔
42
};
3✔
43

44
/**
1✔
45
 * Validates that the end date is not in the past.
46
 */
1✔
47
const endDateNotInPast = (endDate: string) => {
1✔
48
  if (Date.parse(endDate) <= new Date().getTime()) {
3!
49
    return toFail(new ValidationError('End date cannot be in the past.'));
×
50
  }
×
51
  return toPass(endDate);
3✔
52
};
3✔
53

54
/**
1✔
55
 * Full validation spec for BannerRequest. Covers:
56
 * - name: non-empty string
57
 * - duration: positive integer
58
 * - startDate: valid date string
59
 * - endDate: valid date string, after startDate, and not in the past
60
 */
1✔
61
/**
1✔
62
 * Factory that returns a fresh spec per call, preventing ValidationError.join()
63
 * from mutating shared trace instances across requests.
64
 */
1✔
65
export default function bannerRequestSpec(): Specification<BannerRequest, ValidationError> {
1✔
66
  return [
5✔
67
    [stringSpec(), 'name', new ValidationError('name:')],
5✔
68
    [[validDuration], 'duration', new ValidationError('duration:')],
5✔
69
    ...durationSpec<BannerRequest>(),
5✔
70
    [[endDateNotInPast], 'endDate', new ValidationError('endDate:')],
5✔
71
  ];
5✔
72
}
5✔
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc