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

pmcelhaney / counterfact / 8624465510

10 Apr 2024 01:10AM UTC coverage: 86.555% (-0.1%) from 86.664%
8624465510

push

github

web-flow
Merge pull request #844 from pmcelhaney/refactor-path-coder

899 of 991 branches covered (90.72%)

Branch coverage included in aggregate %.

24 of 28 new or added lines in 3 files covered. (85.71%)

2835 of 3323 relevant lines covered (85.31%)

42.54 hits per line

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

95.56
/src/typescript-generator/operation-coder.js
1
/* eslint-disable no-magic-numbers */
2✔
2
import nodePath from "node:path";
2✔
3

2✔
4
import { Coder } from "./coder.js";
2✔
5
import { OperationTypeCoder } from "./operation-type-coder.js";
2✔
6

2✔
7
export class OperationCoder extends Coder {
2✔
8
  constructor(requirement, requestMethod) {
2✔
9
    super(requirement);
54✔
10

54✔
11
    if (requestMethod === undefined) {
54!
NEW
12
      throw new Error("requestMethod is required");
×
NEW
13
    }
×
14

54✔
15
    this.requestMethod = requestMethod;
54✔
16
  }
54✔
17

2✔
18
  names() {
2✔
19
    return super.names(this.requestMethod.toUpperCase());
46✔
20
  }
46✔
21

2✔
22
  write() {
2✔
23
    const responses = this.requirement.get("responses");
48✔
24

48✔
25
    const [firstStatusCode] = responses.map(
48✔
26
      (response, statusCode) => statusCode,
48✔
27
    );
48✔
28
    const [firstResponse] = responses.map((response) => response.data);
48✔
29

48✔
30
    if (!("content" in firstResponse || "schema" in firstResponse)) {
48✔
31
      return `($) => {
12✔
32
        return $.response[${
12✔
33
          firstStatusCode === "default" ? 200 : firstStatusCode
12✔
34
        }];
12✔
35
      }`;
12✔
36
    }
12✔
37

36✔
38
    return `($) => {
36✔
39
      return $.response[${
36✔
40
        firstStatusCode === "default" ? 200 : firstStatusCode
48✔
41
      }].random();
48✔
42
    }`;
48✔
43
  }
48✔
44

2✔
45
  typeDeclaration(namespace, script) {
2✔
46
    const operationTypeCoder = new OperationTypeCoder(
46✔
47
      this.requirement,
46✔
48
      this.requestMethod,
46✔
49
    );
46✔
50

46✔
51
    return script.importType(operationTypeCoder);
46✔
52
  }
46✔
53

2✔
54
  modulePath() {
2✔
55
    const pathString = this.requirement.url
2✔
56
      .split("/")
2✔
57
      .at(-2)
2✔
58
      .replaceAll("~1", "/");
2✔
59

2✔
60
    return `${nodePath
2✔
61
      .join("path", pathString)
2✔
62
      .replaceAll("\\", "/")}.types.ts`;
2✔
63
  }
2✔
64
}
2✔
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

© 2025 Coveralls, Inc