@@ -49,12 +49,12 @@ func TestUserController_Get(t *testing.T) {
49
49
},
50
50
},
51
51
{
52
- name : "存在しないユーザーIDならErrNewErrorNotFound " ,
52
+ name : "存在しないユーザーIDならErrUserNotFound " ,
53
53
userID : "invalid-user-id" ,
54
54
prepareMockUser : func (user * mock.MockUser ) {
55
55
user .EXPECT ().FindByID (gomock .Any (), "invalid-user-id" ).Return (
56
56
nil ,
57
- entity .NewErrorNotFound ( "user" ) ,
57
+ entity .ErrUserNotFound ,
58
58
)
59
59
},
60
60
prepareMockAuth : func (auth * mock.MockAuth ) {},
@@ -312,7 +312,7 @@ func TestUserController_GetPosts(t *testing.T) {
312
312
` ,
313
313
},
314
314
{
315
- name : "1つも投稿が存在しないならErrNewErrorNotFound " ,
315
+ name : "1つも投稿が存在しないならErrUserNotFound " ,
316
316
userID : "user-id2" ,
317
317
prepareMockPost : func (ctx context.Context , uid string , post * mock.MockPost ) {
318
318
post .EXPECT ().FindByUserID (ctx , uid ).Return (nil , entity .NewErrorNotFound ("post" ))
@@ -449,7 +449,7 @@ func TestUserController_Create(t *testing.T) {
449
449
user .EXPECT ().Insert (
450
450
gomock .Any (),
451
451
entity .NewUser ("user-id" , "username" , "profile" , "twitter" , "" ),
452
- ).Return (entity .NewErrorDuplicated ( "user ID" ) )
452
+ ).Return (entity .ErrDuplicatedUser )
453
453
},
454
454
wantErr : true ,
455
455
wantCode : 400 ,
@@ -466,7 +466,7 @@ func TestUserController_Create(t *testing.T) {
466
466
user .EXPECT ().Insert (
467
467
gomock .Any (),
468
468
entity .NewUser ("user-id" , "username" , "profile" , "twitter" , "" ),
469
- ).Return (entity .NewErrorDuplicated ( "user TwitterID" ) )
469
+ ).Return (entity .ErrDuplicatedTwitterID )
470
470
},
471
471
wantErr : true ,
472
472
wantCode : 400 ,
@@ -580,7 +580,7 @@ func TestUserController_Update(t *testing.T) {
580
580
wantCode : 400 ,
581
581
},
582
582
{
583
- name : "存在しないユーザーIDならErrNewErrorNotFound " ,
583
+ name : "存在しないユーザーIDならErrUserNotFound " ,
584
584
userID : "invalid-user-id" ,
585
585
body : `{
586
586
"name":"username",
@@ -590,7 +590,7 @@ func TestUserController_Update(t *testing.T) {
590
590
prepareMockUser : func (user * mock.MockUser ) {
591
591
user .EXPECT ().FindByID (gomock .Any (), "invalid-user-id" ).Return (
592
592
nil ,
593
- entity .NewErrorNotFound ( "user" ) ,
593
+ entity .ErrUserNotFound ,
594
594
)
595
595
},
596
596
prepareMockAuth : func (auth * mock.MockAuth ) {},
@@ -622,7 +622,7 @@ func TestUserController_Update(t *testing.T) {
622
622
for _ , tt := range tests {
623
623
t .Run (tt .name , func (t * testing.T ) {
624
624
e := echo .New ()
625
- req := httptest .NewRequest ("PUT " , "/" , strings .NewReader (tt .body ))
625
+ req := httptest .NewRequest ("POST " , "/" , strings .NewReader (tt .body ))
626
626
req .Header .Set (echo .HeaderContentType , echo .MIMEApplicationJSON )
627
627
rec := httptest .NewRecorder ()
628
628
c := e .NewContext (req , rec )
@@ -661,7 +661,6 @@ func TestUserController_Delete(t *testing.T) {
661
661
tests := []struct {
662
662
name string
663
663
userID string
664
- body string
665
664
prepareMockUser func (user * mock.MockUser )
666
665
prepareMockAuth func (auth * mock.MockAuth )
667
666
wantErr bool
@@ -670,55 +669,22 @@ func TestUserController_Delete(t *testing.T) {
670
669
{
671
670
name : "正しくユーザーを削除できる" ,
672
671
userID : "user-id" ,
673
- body : `{
674
- "name":"name",
675
- "profile":"profile",
676
- "twitter_id":"twitter"
677
- }` ,
678
672
prepareMockUser : func (user * mock.MockUser ) {
679
673
user .EXPECT ().Delete (
680
674
gomock .Any (),
681
- entity .NewUser ("user-id" , "name " , "profile " , "twitter " , "" ),
675
+ entity .NewUser ("user-id" , "" , "" , "" , "" ),
682
676
).Return (nil )
683
677
},
684
678
wantErr : false ,
685
679
wantCode : 200 ,
686
680
},
687
- {
688
- name : "不正なbodyならBadRequest" ,
689
- userID : "user-id" ,
690
- body : `{
691
- "aaa":"test"
692
- }` ,
693
- prepareMockUser : func (user * mock.MockUser ) {
694
- user .EXPECT ().Delete (
695
- gomock .Any (),
696
- entity .NewUser ("user-id" , "" , "" , "" , "" ),
697
- ).Return (entity .NewUser ("user-id" , "" , "" , "" , "" ).IsValid ())
698
- },
699
- wantErr : true ,
700
- wantCode : 400 ,
701
- },
702
- {
703
- name : "bodyがJSON形式でないならBadRequest" ,
704
- userID : "user-id" ,
705
- body : `aaaaa` ,
706
- prepareMockUser : func (user * mock.MockUser ) {},
707
- wantErr : true ,
708
- wantCode : 400 ,
709
- },
710
681
{
711
682
name : "存在しないユーザーIDならErrNewErrorNotFound" ,
712
683
userID : "invalid-user-id" ,
713
- body : `{
714
- "name":"username",
715
- "profile":"profile",
716
- "twitter_id":"twitter"
717
- }` ,
718
684
prepareMockUser : func (user * mock.MockUser ) {
719
685
user .EXPECT ().Delete (
720
686
gomock .Any (),
721
- entity .NewUser ("invalid-user-id" , "username " , "profile " , "twitter " , "" ),
687
+ entity .NewUser ("invalid-user-id" , "" , "" , "" , "" ),
722
688
).Return (entity .NewErrorNotFound ("user" ))
723
689
},
724
690
prepareMockAuth : func (auth * mock.MockAuth ) {},
@@ -728,15 +694,10 @@ func TestUserController_Delete(t *testing.T) {
728
694
{
729
695
name : "別のユーザが削除しようとしているならErrIsNotAuthorでStatusForbidden" ,
730
696
userID : "user-id2" ,
731
- body : `{
732
- "name":"name",
733
- "profile":"profile",
734
- "twitter_id":"twitter"
735
- }` ,
736
697
prepareMockUser : func (user * mock.MockUser ) {
737
698
user .EXPECT ().Delete (
738
699
gomock .Any (),
739
- entity .NewUser ("user-id2" , "name " , "profile " , "twitter " , "" ),
700
+ entity .NewUser ("user-id2" , "" , "" , "" , "" ),
740
701
).Return (entity .ErrIsNotAuthor )
741
702
},
742
703
wantErr : true ,
@@ -746,7 +707,7 @@ func TestUserController_Delete(t *testing.T) {
746
707
for _ , tt := range tests {
747
708
t .Run (tt .name , func (t * testing.T ) {
748
709
e := echo .New ()
749
- req := httptest .NewRequest ("DELETE" , "/" , strings . NewReader ( tt . body ) )
710
+ req := httptest .NewRequest ("DELETE" , "/" , nil )
750
711
req .Header .Set (echo .HeaderContentType , echo .MIMEApplicationJSON )
751
712
rec := httptest .NewRecorder ()
752
713
c := e .NewContext (req , rec )
0 commit comments