File size: 1,579 Bytes
5743bc2
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
type ScanReportLike = {
  trustScore: number;
  falseUrgency: { detected: boolean };
  falseScarcity: { detected: boolean };
  confirmShaming: { detected: boolean };
  hiddenFees: { detected: boolean };
  preCheckedAddOns: { detected: boolean };
  misdirection: { detected: boolean };
  summary: string;
};

export function buildDetectionReportInsert(input: {
  domain: string;
  url: string;
  darkPatternReport: ScanReportLike;
  totalPatternsDetected: number;
  hiddenFeesTotal: number | null;
}) {
  return {
    domain: input.domain,
    url: input.url,
    trustScore: input.darkPatternReport.trustScore,
    falseUrgencyDetected: input.darkPatternReport.falseUrgency.detected,
    falseScarcityDetected: input.darkPatternReport.falseScarcity.detected,
    confirmShamingDetected: input.darkPatternReport.confirmShaming.detected,
    hiddenFeesDetected: input.darkPatternReport.hiddenFees.detected,
    preCheckedAddOnsDetected: input.darkPatternReport.preCheckedAddOns.detected,
    misdirectionDetected: input.darkPatternReport.misdirection.detected,
    totalPatternsDetected: input.totalPatternsDetected,
    hiddenFeesTotal: input.hiddenFeesTotal,
    summary: input.darkPatternReport.summary,
  };
}

export function buildMockDetectionReport(input: {
  id: number;
  domain: string;
  url: string;
  darkPatternReport: ScanReportLike;
  totalPatternsDetected: number;
  hiddenFeesTotal: number | null;
  createdAt?: string;
}) {
  return {
    id: input.id,
    ...buildDetectionReportInsert(input),
    createdAt: input.createdAt ?? new Date().toISOString(),
  };
}