示例#1
0
func Test_UpdateStatus(t *testing.T) {
	subs, db := setup(t, "submission")
	defer teardown(t, db)

	t.Log("Given the need to update the status of a submission.")
	{
		t.Log("\tWhen starting from an empty submissions collection")
		{

			//----------------------------------------------------------------------
			// Create the submission.

			if err := submission.Create(tests.Context, db, subs[0].FormID.Hex(), &subs[0]); err != nil {
				t.Fatalf("\t%s\tShould be able to create a submission : %s", tests.Failed, err)
			}
			t.Logf("\t%s\tShould be able to create a submission.", tests.Success)

			sub, err := submission.Retrieve(tests.Context, db, subs[0].ID.Hex())
			if err != nil {
				t.Fatalf("\t%s\tShould be able to retrieve the submission : %s", tests.Failed, err.Error())
			}
			t.Logf("\t%s\tShould be able to retrieve the submission", tests.Success)

			newStatus := time.Now().String()

			//----------------------------------------------------------------------
			// Update the submission's status.

			nsub, err := submission.UpdateStatus(tests.Context, db, sub.ID.Hex(), newStatus)
			if err != nil {
				t.Fatalf("\t%s\tShould be able to update the submission status : %s", tests.Failed, err.Error())
			}
			t.Logf("\t%s\tShould be able to update the submission status", tests.Success)

			//----------------------------------------------------------------------
			// Ensure that the status was updated on the returned submission.

			if nsub.Status != newStatus {
				t.Fatalf("\t%s\tShould be able to update the submission status : Expected %s, got %s", tests.Failed, newStatus, nsub.Status)
			}
			t.Logf("\t%s\tShould be able to update the submission status", tests.Success)

			//----------------------------------------------------------------------
			// Ensure that the status was updated on the stored submission.

			rsub, err := submission.Retrieve(tests.Context, db, sub.ID.Hex())
			if err != nil {
				t.Fatalf("\t%s\tShould be able to retrieve the submission : %s", tests.Failed, err.Error())
			}
			t.Logf("\t%s\tShould be able to retrieve the submission", tests.Success)

			if rsub.Status != newStatus {
				t.Fatalf("\t%s\tShould be able to update the submission status in the store : Expected %s, got %s", tests.Failed, newStatus, nsub.Status)
			}
			t.Logf("\t%s\tShould be able to update the submission status in the store", tests.Success)
		}
	}
}
示例#2
0
// UpdateStatus updates the status of a FormSubmission based on the route
// params.
// 200 Success, 400 Bad Request, 404 Not Found, 500 Internal
func (formSubmissionHandle) UpdateStatus(c *web.Context) error {
	id := c.Params["id"]
	status := c.Params["status"]

	s, err := submission.UpdateStatus(c.SessionID, c.Ctx["DB"].(*db.DB), id, status)
	if err != nil {
		return err
	}

	c.Respond(s, http.StatusOK)

	return nil
}