evaluation_test.gno

2.12 Kb ยท 73 lines
 1package evaluation
 2
 3/*
 4	1. At what stage of the PR a contribution should be evaluated?
 5		Should the PR be approved first?
 6	2. Can a contribution be re-evaluated before approved (current assumption is once a contribution is approved its state is final)?
 7	3. Can an evaluation criteria change up until it is approved (current assumption is that the evaluation criteria is set when the contribution is added)?
 8*/
 9
10import (
11	"testing"
12
13	"gno.land/p/nt/testutils"
14	"gno.land/p/nt/ufmt"
15)
16
17var (
18	e = NewEvalutaion()
19
20	id          = 792
21	name        = "Evaluation DAO Kick Off"
22	description = "The PR is to initiate a discussion regarding the evaluation DAO"
23	status      = "Draft"
24	category    = "feat"
25	criteria    = map[string]int32{"simplicity": 1, "usefullnes": 1, "quality": 1}
26	address_XXX = testutils.TestAddress("contributor")
27)
28
29func TestEvaluationAddContribution(t *testing.T) {
30	pr := NewPullRequest(id, name, description, status, category)
31	contributionId, _ := e.AddContribution(pr, address_XXX)
32
33	t.Run("", func(t *testing.T) {
34		if contributionId != id {
35			t.Errorf("Got Contribution Id %d expected %d", contributionId, id)
36		}
37	})
38
39	t.Run("Contribution added using the pull request id", func(t *testing.T) {
40		c, _ := e.contributions.Get(ufmt.Sprintf("%d", id))
41		contribtution := c.(*Contribution)
42		if contribtution.Id() != id {
43			t.Errorf("Got Contribution Id %d expected %d", contribtution.Id(), id)
44		}
45	})
46
47	t.Run("Pull Request added using the pull request id", func(t *testing.T) {
48		pr, _ := e.pullrequests.Get(ufmt.Sprintf("%d", id))
49		pullrequest := pr.(*PullRequest)
50		if pullrequest.Id() != id {
51			t.Errorf("Got Pull Request Id %d expected %d", pullrequest.Id(), id)
52		}
53	})
54}
55
56func TestEvaluationUpdateContribution(t *testing.T) {
57	t.Run("", func(t *testing.T) {
58		status := "Negotiated"
59		ok := e.UpdateContribution(id, status)
60		if !ok {
61			t.Error("Expected evaluation to update contribution's status successfully but failed")
62		}
63	})
64
65	t.Run("Contribution doesn't exist", func(t *testing.T) {
66		id := 1
67		status := "Negotiated"
68		ok := e.UpdateContribution(id, status)
69		if ok {
70			t.Error("Expected evaluation to fail but pass")
71		}
72	})
73}