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

goto / guardian / 9576502514

19 Jun 2024 05:10AM UTC coverage: 74.953% (+0.1%) from 74.806%
9576502514

push

github

web-flow
fix(edit-appeal): check details interface recursively to validate if fields are changed (#157)

* feat(edit-appeal): check details interface recursively to validate if any field value is changed or not

* feat(edit-appeal): send pre condition failed error in case of no changes found

* chore: fixed go releaser version

* refactor: rely on approval.Index instead of array index when evaluating list of approvals

* chore: add TODO to check appeal.status directly

* fix: loop through approvals by policy steps

* fix: return next non-stale pending approval

* chore: add comment

* test: update test cases for update approval to cover appeal containing stale approvals

* test: update test cases for AdvanceApproval

* fix(diff): change default behavior and add tests

* refactor: fully use diff.Compare to compare old and new appeals

* refactor: move appeal diff logic to domain

* refactor: centralized appeal details reserved keys

---------

Co-authored-by: Ayushi Sharma <ayushi.sharma@gojek.com>
Co-authored-by: Rahmat Hidayat <rahmatramahidayat@gmail.com>

214 of 248 new or added lines in 5 files covered. (86.29%)

4 existing lines in 2 files now uncovered.

10073 of 13439 relevant lines covered (74.95%)

4.9 hits per line

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

85.37
/pkg/diff/diff.go
1
package diff
2

3
import (
4
        "encoding/json"
5
        "fmt"
6
        "strings"
7

8
        "github.com/wI2L/jsondiff"
9
)
10

11
type Change struct {
12
        Op       string
13
        Path     string
14
        OldValue any
15
        NewValue any
16
}
17

18
func Compare(a, b any) ([]*Change, error) {
8✔
19
        jsonA, err := json.Marshal(a)
8✔
20
        if err != nil {
8✔
NEW
21
                return nil, fmt.Errorf("failed to marshal a: %w", err)
×
22
        }
×
23

24
        jsonB, err := json.Marshal(b)
8✔
25
        if err != nil {
8✔
NEW
26
                return nil, fmt.Errorf("failed to marshal b: %w", err)
×
27
        }
×
28

29
        diff, err := jsondiff.CompareJSON(jsonA, jsonB)
8✔
30
        if err != nil {
8✔
31
                return nil, err
×
32
        }
×
33
        if diff == nil {
9✔
34
                return nil, nil
1✔
35
        }
1✔
36

37
        changes := make([]*Change, 0, len(diff))
7✔
38
        for _, d := range diff {
19✔
39
                changes = append(changes, &Change{
12✔
40
                        Op:       d.Type,
12✔
41
                        Path:     transformPath(d.Path),
12✔
42
                        NewValue: d.Value,
12✔
43
                        OldValue: d.OldValue,
12✔
44
                })
12✔
45
        }
12✔
46
        return changes, nil
7✔
47
}
48

49
func transformPath(path string) string {
12✔
50
        result := path
12✔
51
        result = strings.TrimPrefix(result, "/")
12✔
52

12✔
53
        // escape . to \.
12✔
54
        result = strings.ReplaceAll(result, ".", "\\.")
12✔
55

12✔
56
        // unescape ~1 to / and ~0 to ~ as per RFC 6901
12✔
57
        result = strings.ReplaceAll(result, "~1", "/")
12✔
58
        result = strings.ReplaceAll(result, "~0", "~")
12✔
59

12✔
60
        // use dot as separator
12✔
61
        result = strings.ReplaceAll(result, "/", ".")
12✔
62
        return result
12✔
63
}
12✔
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