|
21 | 21 | ) |
22 | 22 |
|
23 | 23 | func TestRepo_CreateApproval(t *testing.T) { |
| 24 | + t.Run("Validate to request the approval to the deployer.", func(t *testing.T) { |
| 25 | + input := struct { |
| 26 | + number int |
| 27 | + payload *approvalPostPayload |
| 28 | + }{ |
| 29 | + number: 7, |
| 30 | + payload: &approvalPostPayload{ |
| 31 | + UserID: 4, |
| 32 | + }, |
| 33 | + } |
| 34 | + |
| 35 | + ctrl := gomock.NewController(t) |
| 36 | + m := mock.NewMockInteractor(ctrl) |
| 37 | + |
| 38 | + t.Log("MOCK - Find the deployment by ID.") |
| 39 | + m. |
| 40 | + EXPECT(). |
| 41 | + FindDeploymentOfRepoByNumber(ctx, any, input.number). |
| 42 | + Return(&ent.Deployment{ |
| 43 | + ID: input.number, |
| 44 | + Edges: ent.DeploymentEdges{ |
| 45 | + User: &ent.User{ |
| 46 | + ID: input.payload.UserID, |
| 47 | + }, |
| 48 | + }, |
| 49 | + }, nil) |
| 50 | + |
| 51 | + t.Log("MOCK - Find the user, and check the permission.") |
| 52 | + m. |
| 53 | + EXPECT(). |
| 54 | + FindUserByID(ctx, input.payload.UserID). |
| 55 | + Return(&ent.User{ |
| 56 | + ID: input.payload.UserID, |
| 57 | + }, nil) |
| 58 | + |
| 59 | + m. |
| 60 | + EXPECT(). |
| 61 | + FindPermOfRepo(ctx, any, &ent.User{ |
| 62 | + ID: input.payload.UserID, |
| 63 | + }). |
| 64 | + Return(&ent.Perm{}, nil) |
| 65 | + |
| 66 | + gin.SetMode(gin.ReleaseMode) |
| 67 | + |
| 68 | + r := NewRepo(RepoConfig{}, m) |
| 69 | + router := gin.New() |
| 70 | + router.POST("/deployments/:number/approvals", func(c *gin.Context) { |
| 71 | + c.Set(KeyRepo, &ent.Repo{}) |
| 72 | + }, r.CreateApproval) |
| 73 | + |
| 74 | + body, _ := json.Marshal(input.payload) |
| 75 | + req, _ := http.NewRequest("POST", fmt.Sprintf("/deployments/%d/approvals", input.number), bytes.NewBuffer(body)) |
| 76 | + |
| 77 | + w := httptest.NewRecorder() |
| 78 | + router.ServeHTTP(w, req) |
| 79 | + |
| 80 | + if w.Code != http.StatusUnprocessableEntity { |
| 81 | + t.Fatalf("Code != %d, wanted %d", w.Code, http.StatusOK) |
| 82 | + } |
| 83 | + }) |
24 | 84 |
|
25 | 85 | t.Run("Create a new approval.", func(t *testing.T) { |
26 | 86 | input := struct { |
|
0 commit comments