web/src/utils/security-check-mappings.test.ts
68 lines · 2464 bytes
1import { describe, it, expect } from 'vitest';
2import { analyzeSecurityChecks } from './security-check-mappings';
3
4describe('analyzeSecurityChecks', () => {
5 it('classifies a passing HTTPS check as passed', () => {
6 const { passedChecks, failedChecks } = analyzeSecurityChecks({
7 is_valid_https: true,
8 });
9 expect(passedChecks).toContain('Valid HTTPS Connection');
10 expect(failedChecks).toHaveLength(0);
11 });
12
13 it('classifies is_valid_https: "no" as failed', () => {
14 // The pass logic uses (value === shouldPass) || (shouldPass === true && value !== "no")
15 // For boolean false, the second condition still passes (false !== "no" is true).
16 // Only the string "no" actually triggers a failure when shouldPass is true.
17 const { failedChecks } = analyzeSecurityChecks({
18 is_valid_https: 'no',
19 });
20 expect(failedChecks).toContain('Valid HTTPS Connection');
21 });
22
23 it('classifies a false-means-pass check correctly', () => {
24 // is_host_an_ipv4 should be false to pass
25 const { passedChecks } = analyzeSecurityChecks({
26 is_host_an_ipv4: false,
27 });
28 expect(passedChecks).toContain('Host is an IPv4 Address');
29 });
30
31 it('classifies a false-means-pass check as failed when true', () => {
32 const { failedChecks } = analyzeSecurityChecks({
33 is_host_an_ipv4: true,
34 });
35 expect(failedChecks).toContain('Host is an IPv4 Address');
36 });
37
38 it('handles multiple checks at once', () => {
39 const { passedChecks, failedChecks } = analyzeSecurityChecks({
40 is_valid_https: true,
41 is_host_an_ipv4: false,
42 is_suspended_page: true, // should fail (expected false)
43 });
44 expect(passedChecks).toHaveLength(2);
45 expect(failedChecks).toHaveLength(1);
46 expect(failedChecks).toContain('Suspended Page');
47 });
48
49 it('handles string "no" values for domain_recent checks', () => {
50 const { passedChecks } = analyzeSecurityChecks({
51 is_domain_recent: 'no',
52 });
53 expect(passedChecks).toContain('Domain Recently Created');
54 });
55
56 it('fails domain_recent when value is not "no"', () => {
57 const { failedChecks } = analyzeSecurityChecks({
58 is_domain_recent: 'yes',
59 });
60 expect(failedChecks).toContain('Domain Recently Created');
61 });
62
63 it('returns empty arrays for empty input', () => {
64 const { passedChecks, failedChecks } = analyzeSecurityChecks({});
65 expect(passedChecks).toHaveLength(0);
66 expect(failedChecks).toHaveLength(0);
67 });
68});