|
| 1 | +// SPDX-License-Identifier: AGPL-3.0-only |
| 2 | +// |
| 3 | +// This program is free software: you can redistribute it and/or modify |
| 4 | +// it under the terms of the GNU Affero General Public License as published |
| 5 | +// by the Free Software Foundation, version 3. |
| 6 | +// |
| 7 | +// This program is distributed in the hope that it will be useful, |
| 8 | +// but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 9 | +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. |
| 10 | +// See the GNU Affero General Public License for more details. |
| 11 | +// |
| 12 | +// You should have received a copy of the GNU Affero General Public License |
| 13 | +// along with this program. If not, see <https://www.gnu.org/licenses/> |
| 14 | + |
| 15 | +package user_test |
| 16 | + |
| 17 | +import ( |
| 18 | + "fmt" |
| 19 | + "net/http" |
| 20 | + "testing" |
| 21 | + |
| 22 | + "github.com/labstack/echo/v4" |
| 23 | + "github.com/stretchr/testify/mock" |
| 24 | + "github.com/trim21/htest" |
| 25 | + |
| 26 | + "github.com/bangumi/server/internal/auth" |
| 27 | + "github.com/bangumi/server/internal/mocks" |
| 28 | + "github.com/bangumi/server/internal/model" |
| 29 | + "github.com/bangumi/server/internal/pkg/test" |
| 30 | +) |
| 31 | + |
| 32 | +func TestUser_DeleteSubjectCollection(t *testing.T) { |
| 33 | + t.Parallel() |
| 34 | + const uid model.UserID = 1 |
| 35 | + const sid model.SubjectID = 8 |
| 36 | + |
| 37 | + a := mocks.NewAuthService(t) |
| 38 | + a.EXPECT().GetByToken(mock.Anything, mock.Anything).Return(auth.Auth{ID: uid}, nil) |
| 39 | + |
| 40 | + c := mocks.NewCollectionRepo(t) |
| 41 | + c.EXPECT().DeleteSubjectCollection(mock.Anything, uid, sid). |
| 42 | + Return(nil) |
| 43 | + |
| 44 | + app := test.GetWebApp(t, test.Mock{CollectionRepo: c, AuthService: a}) |
| 45 | + |
| 46 | + htest.New(t, app). |
| 47 | + Header(echo.HeaderAuthorization, "Bearer t"). |
| 48 | + Delete(fmt.Sprintf("/v0/users/-/collections/%d", sid)). |
| 49 | + ExpectCode(http.StatusNoContent) |
| 50 | +} |
0 commit comments