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

digaev / interactor-js / 6656e8ee-9903-4023-ba76-c2dc6937abc6

24 Jun 2024 03:55PM UTC coverage: 99.074%. Remained the same
6656e8ee-9903-4023-ba76-c2dc6937abc6

push

circleci

web-flow
Update README.md

23 of 24 branches covered (95.83%)

Branch coverage included in aggregate %.

84 of 84 relevant lines covered (100.0%)

4.68 hits per line

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

96.43
/lib/interactor.ts
1
/* eslint-disable class-methods-use-this */
2

3
export default class Interactor {
1✔
4
  #context: any;
16✔
5

6
  #failure = false;
16✔
7

8
  get context() {
9
    return this.#context;
4✔
10
  }
11

12
  get failure() {
13
    return this.#failure;
3✔
14
  }
15

16
  get success() {
17
    return !this.#failure;
27✔
18
  }
19

20
  static async perform<T extends Interactor = Interactor>(context: any = {}): Promise<T> {
1✔
21
    const interactor = new this(context);
10✔
22

23
    return interactor.perform().then(() => interactor as T);
10✔
24
  }
25

26
  constructor(context: any = {}) {
6✔
27
    this.#context = context;
16✔
28

29
    this.around();
16✔
30
  }
31

32
  public after(): Promise<any> {
33
    return Promise.resolve();
10✔
34
  }
35

36
  public before(): Promise<any> {
37
    return Promise.resolve();
14✔
38
  }
39

40
  public fail(context: any = {}): void {
×
41
    this.#failure = true;
4✔
42

43
    Object.keys(context).forEach((k) => {
4✔
44
      this.#context[k] = context[k];
4✔
45
    });
46
  }
47

48
  public perform(): Promise<any> {
49
    return Promise.resolve();
8✔
50
  }
51

52
  public rollback(): Promise<any> {
53
    return Promise.resolve();
5✔
54
  }
55

56
  protected around(): void {
57
    const original = this.perform;
16✔
58

59
    this.perform = () => Promise.resolve(this.before())
16✔
60
      .then(() => original.call(this))
16✔
61
      .then((result) => {
62
        if (this.success) {
15✔
63
          return Promise.resolve(this.after()).then(() => result);
12✔
64
        }
65
        return result;
3✔
66
      });
67
  }
68
}
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