MCPcopy Create free account
hub / github.com/Creatly/creatly-backend / TestAdminCreateCourse

Method TestAdminCreateCourse

tests/admins_test.go:15–50  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

13)
14
15func (s *APITestSuite) TestAdminCreateCourse() {
16 router := gin.New()
17 s.handler.Init(router.Group("/api"))
18 r := s.Require()
19
20 // populate DB data
21 id := primitive.NewObjectID()
22 schoolID := primitive.NewObjectID()
23 adminEmail, password := "testAdmin@test.com", "qwerty123"
24 passwordHash, err := s.hasher.Hash(password)
25 s.NoError(err)
26
27 _, err = s.db.Collection("admins").InsertOne(context.Background(), domain.Admin{
28 ID: id,
29 Email: adminEmail,
30 Password: passwordHash,
31 SchoolID: schoolID,
32 })
33 s.NoError(err)
34
35 jwt, err := s.getJwt(id)
36 s.NoError(err)
37
38 adminCourseName := "admin course test name"
39
40 name := fmt.Sprintf(`{"name":"%s"}`, adminCourseName)
41
42 req, _ := http.NewRequest("POST", "/api/v1/admins/courses", strings.NewReader(name))
43 req.Header.Set("Content-type", "application/json")
44 req.Header.Set("Authorization", "Bearer "+jwt)
45
46 resp := httptest.NewRecorder()
47 router.ServeHTTP(resp, req)
48
49 r.Equal(http.StatusCreated, resp.Result().StatusCode)
50}
51
52func (s *APITestSuite) TestAdminGetAllCourses() {
53 router := gin.New()

Callers

nothing calls this directly

Calls 4

getJwtMethod · 0.95
HashMethod · 0.65
SetMethod · 0.65
InitMethod · 0.45

Tested by

no test coverage detected