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

vocdoni / saas-backend / 16301338771

15 Jul 2025 06:29PM UTC coverage: 56.793% (+0.7%) from 56.082%
16301338771

Pull #165

github

emmdim
refactor:  census creation

- Removed the PublishedCensus type and added it as Census parameter.
- Introduced new OrgMemberAuthFields defining the data options for member authentication.
- Added the `CheckOrgMemberAuthFields` function that checks a set of members and given auth fields empties an
d duplicates
- Add the option to create a census through the api based on a given group
Pull Request #165: Implements group based census creation

250 of 399 new or added lines in 9 files covered. (62.66%)

4 existing lines in 3 files now uncovered.

5104 of 8987 relevant lines covered (56.79%)

25.32 hits per line

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

87.76
/db/process.go
1
package db
2

3
import (
4
        "context"
5
        "fmt"
6

7
        "go.mongodb.org/mongo-driver/bson"
8
)
9

10
// CreateProcess creates a new process for an organization
11
func (ms *MongoStorage) SetProcess(process *Process) error {
21✔
12
        if len(process.ID) == 0 || len(process.OrgAddress) == 0 || len(process.Census.ID) == 0 {
23✔
13
                return ErrInvalidData
2✔
14
        }
2✔
15

16
        // check that the org exists
17
        if _, err := ms.Organization(process.OrgAddress); err != nil {
20✔
18
                return fmt.Errorf("failed to get organization: %w", err)
1✔
19
        }
1✔
20
        // check that the census exists
21
        census, err := ms.Census(process.Census.ID.Hex())
18✔
22
        if err != nil {
18✔
NEW
23
                return fmt.Errorf("failed to get census: %w", err)
×
UNCOV
24
        }
×
25
        if len(census.Published.Root) == 0 || len(census.Published.URI) == 0 {
19✔
26
                return fmt.Errorf("census %s does not have a published root or URI", census.ID.Hex())
1✔
27
        }
1✔
28

29
        // TODO create the census if not found?
30

31
        ms.keysLock.Lock()
17✔
32
        defer ms.keysLock.Unlock()
17✔
33
        // create a context with a timeout
17✔
34
        ctx, cancel := context.WithTimeout(context.Background(), defaultTimeout)
17✔
35
        defer cancel()
17✔
36
        if _, err := ms.processes.InsertOne(ctx, process); err != nil {
17✔
UNCOV
37
                return fmt.Errorf("failed to create process: %w", err)
×
38
        }
×
39

40
        return nil
17✔
41
}
42

43
// DeleteProcess removes a process
44
func (ms *MongoStorage) DelProcess(processID []byte) error {
2✔
45
        if len(processID) == 0 {
3✔
46
                return ErrInvalidData
1✔
47
        }
1✔
48
        ms.keysLock.Lock()
1✔
49
        defer ms.keysLock.Unlock()
1✔
50
        // create a context with a timeout
1✔
51
        ctx, cancel := context.WithTimeout(context.Background(), defaultTimeout)
1✔
52
        defer cancel()
1✔
53

1✔
54
        // delete the process from the database using the ID
1✔
55
        filter := bson.M{"_id": processID}
1✔
56
        _, err := ms.processes.DeleteOne(ctx, filter)
1✔
57
        return err
1✔
58
}
59

60
// Process retrieves a process from the DB based on its ID
61
func (ms *MongoStorage) Process(processID []byte) (*Process, error) {
5✔
62
        if len(processID) == 0 {
5✔
63
                return nil, ErrInvalidData
×
64
        }
×
65

66
        // create a context with a timeout
67
        ctx, cancel := context.WithTimeout(context.Background(), defaultTimeout)
5✔
68
        defer cancel()
5✔
69

5✔
70
        process := &Process{}
5✔
71
        if err := ms.processes.FindOne(ctx, bson.M{"_id": processID}).Decode(process); err != nil {
9✔
72
                return nil, fmt.Errorf("failed to get process: %w", err)
4✔
73
        }
4✔
74

75
        return process, nil
1✔
76
}
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