|
| 1 | +package handler |
| 2 | + |
| 3 | +import ( |
| 4 | + "context" |
| 5 | + "errors" |
| 6 | + "reflect" |
| 7 | + "testing" |
| 8 | + |
| 9 | + "github.com/zoobc/zoobc-core/api/service" |
| 10 | + "github.com/zoobc/zoobc-core/common/model" |
| 11 | +) |
| 12 | + |
| 13 | +type ( |
| 14 | + mockGetPendingTransactionsError struct { |
| 15 | + service.MultisigServiceInterface |
| 16 | + } |
| 17 | + mockGetPendingTransactionsSuccess struct { |
| 18 | + service.MultisigServiceInterface |
| 19 | + } |
| 20 | +) |
| 21 | + |
| 22 | +func (*mockGetPendingTransactionsError) GetPendingTransactions(param *model.GetPendingTransactionsRequest, |
| 23 | +) (*model.GetPendingTransactionsResponse, error) { |
| 24 | + return nil, errors.New("Error GetPendingTransactions") |
| 25 | +} |
| 26 | + |
| 27 | +func (*mockGetPendingTransactionsSuccess) GetPendingTransactions(param *model.GetPendingTransactionsRequest, |
| 28 | +) (*model.GetPendingTransactionsResponse, error) { |
| 29 | + return &model.GetPendingTransactionsResponse{}, nil |
| 30 | +} |
| 31 | + |
| 32 | +func TestMultisigHandler_GetPendingTransactions(t *testing.T) { |
| 33 | + type fields struct { |
| 34 | + MultisigService service.MultisigServiceInterface |
| 35 | + } |
| 36 | + type args struct { |
| 37 | + ctx context.Context |
| 38 | + req *model.GetPendingTransactionsRequest |
| 39 | + } |
| 40 | + tests := []struct { |
| 41 | + name string |
| 42 | + fields fields |
| 43 | + args args |
| 44 | + want *model.GetPendingTransactionsResponse |
| 45 | + wantErr bool |
| 46 | + }{ |
| 47 | + { |
| 48 | + name: "GetPendingTransactions:ErrorPageLessThanOne", |
| 49 | + args: args{ |
| 50 | + req: &model.GetPendingTransactionsRequest{ |
| 51 | + Pagination: &model.Pagination{ |
| 52 | + Page: 0, |
| 53 | + }, |
| 54 | + }, |
| 55 | + }, |
| 56 | + want: nil, |
| 57 | + wantErr: true, |
| 58 | + }, |
| 59 | + { |
| 60 | + name: "GetPendingTransactions:Error", |
| 61 | + args: args{ |
| 62 | + req: &model.GetPendingTransactionsRequest{ |
| 63 | + Pagination: &model.Pagination{ |
| 64 | + Page: 1, |
| 65 | + }, |
| 66 | + }, |
| 67 | + }, |
| 68 | + fields: fields{ |
| 69 | + MultisigService: &mockGetPendingTransactionsError{}, |
| 70 | + }, |
| 71 | + want: nil, |
| 72 | + wantErr: true, |
| 73 | + }, |
| 74 | + { |
| 75 | + name: "GetPendingTransactions:Success", |
| 76 | + args: args{ |
| 77 | + req: &model.GetPendingTransactionsRequest{ |
| 78 | + Pagination: &model.Pagination{ |
| 79 | + Page: 1, |
| 80 | + }, |
| 81 | + }, |
| 82 | + }, |
| 83 | + fields: fields{ |
| 84 | + MultisigService: &mockGetPendingTransactionsSuccess{}, |
| 85 | + }, |
| 86 | + want: &model.GetPendingTransactionsResponse{}, |
| 87 | + wantErr: false, |
| 88 | + }, |
| 89 | + } |
| 90 | + for _, tt := range tests { |
| 91 | + t.Run(tt.name, func(t *testing.T) { |
| 92 | + msh := &MultisigHandler{ |
| 93 | + MultisigService: tt.fields.MultisigService, |
| 94 | + } |
| 95 | + got, err := msh.GetPendingTransactions(tt.args.ctx, tt.args.req) |
| 96 | + if (err != nil) != tt.wantErr { |
| 97 | + t.Errorf("MultisigHandler.GetPendingTransactions() error = %v, wantErr %v", err, tt.wantErr) |
| 98 | + return |
| 99 | + } |
| 100 | + if !reflect.DeepEqual(got, tt.want) { |
| 101 | + t.Errorf("MultisigHandler.GetPendingTransactions() = %v, want %v", got, tt.want) |
| 102 | + } |
| 103 | + }) |
| 104 | + } |
| 105 | +} |
| 106 | + |
| 107 | +type ( |
| 108 | + mockGetPendingTransactionDetailByTransactionHashError struct { |
| 109 | + service.MultisigServiceInterface |
| 110 | + } |
| 111 | + mockGetPendingTransactionDetailByTransactionHashSuccess struct { |
| 112 | + service.MultisigServiceInterface |
| 113 | + } |
| 114 | +) |
| 115 | + |
| 116 | +func (*mockGetPendingTransactionDetailByTransactionHashError) GetPendingTransactionDetailByTransactionHash( |
| 117 | + param *model.GetPendingTransactionDetailByTransactionHashRequest) (*model.GetPendingTransactionDetailByTransactionHashResponse, error) { |
| 118 | + return nil, errors.New("Error GetPendingTransactionDetailByTransactionHash") |
| 119 | +} |
| 120 | + |
| 121 | +func (*mockGetPendingTransactionDetailByTransactionHashSuccess) GetPendingTransactionDetailByTransactionHash( |
| 122 | + param *model.GetPendingTransactionDetailByTransactionHashRequest) (*model.GetPendingTransactionDetailByTransactionHashResponse, error) { |
| 123 | + return &model.GetPendingTransactionDetailByTransactionHashResponse{}, nil |
| 124 | +} |
| 125 | + |
| 126 | +func TestMultisigHandler_GetPendingTransactionDetailByTransactionHash(t *testing.T) { |
| 127 | + type fields struct { |
| 128 | + MultisigService service.MultisigServiceInterface |
| 129 | + } |
| 130 | + type args struct { |
| 131 | + ctx context.Context |
| 132 | + req *model.GetPendingTransactionDetailByTransactionHashRequest |
| 133 | + } |
| 134 | + tests := []struct { |
| 135 | + name string |
| 136 | + fields fields |
| 137 | + args args |
| 138 | + want *model.GetPendingTransactionDetailByTransactionHashResponse |
| 139 | + wantErr bool |
| 140 | + }{ |
| 141 | + { |
| 142 | + name: "GetPendingTransactionDetailByTransactionHash:Error", |
| 143 | + fields: fields{ |
| 144 | + MultisigService: &mockGetPendingTransactionDetailByTransactionHashError{}, |
| 145 | + }, |
| 146 | + want: nil, |
| 147 | + wantErr: true, |
| 148 | + }, |
| 149 | + { |
| 150 | + name: "GetPendingTransactionDetailByTransactionHash:Success", |
| 151 | + fields: fields{ |
| 152 | + MultisigService: &mockGetPendingTransactionDetailByTransactionHashSuccess{}, |
| 153 | + }, |
| 154 | + want: &model.GetPendingTransactionDetailByTransactionHashResponse{}, |
| 155 | + wantErr: false, |
| 156 | + }, |
| 157 | + } |
| 158 | + for _, tt := range tests { |
| 159 | + t.Run(tt.name, func(t *testing.T) { |
| 160 | + msh := &MultisigHandler{ |
| 161 | + MultisigService: tt.fields.MultisigService, |
| 162 | + } |
| 163 | + got, err := msh.GetPendingTransactionDetailByTransactionHash(tt.args.ctx, tt.args.req) |
| 164 | + if (err != nil) != tt.wantErr { |
| 165 | + t.Errorf("MultisigHandler.GetPendingTransactionDetailByTransactionHash() error = %v, wantErr %v", err, tt.wantErr) |
| 166 | + return |
| 167 | + } |
| 168 | + if !reflect.DeepEqual(got, tt.want) { |
| 169 | + t.Errorf("MultisigHandler.GetPendingTransactionDetailByTransactionHash() = %v, want %v", got, tt.want) |
| 170 | + } |
| 171 | + }) |
| 172 | + } |
| 173 | +} |
| 174 | + |
| 175 | +type ( |
| 176 | + mockGetMultisignatureInfoError struct { |
| 177 | + service.MultisigServiceInterface |
| 178 | + } |
| 179 | + mockGetMultisignatureInfoSuccess struct { |
| 180 | + service.MultisigServiceInterface |
| 181 | + } |
| 182 | +) |
| 183 | + |
| 184 | +func (*mockGetMultisignatureInfoError) GetMultisignatureInfo(param *model.GetMultisignatureInfoRequest, |
| 185 | +) (*model.GetMultisignatureInfoResponse, error) { |
| 186 | + return nil, errors.New("Error GetMultisignatureInfo") |
| 187 | +} |
| 188 | + |
| 189 | +func (*mockGetMultisignatureInfoSuccess) GetMultisignatureInfo(param *model.GetMultisignatureInfoRequest, |
| 190 | +) (*model.GetMultisignatureInfoResponse, error) { |
| 191 | + return &model.GetMultisignatureInfoResponse{}, nil |
| 192 | +} |
| 193 | + |
| 194 | +func TestMultisigHandler_GetMultisignatureInfo(t *testing.T) { |
| 195 | + type fields struct { |
| 196 | + MultisigService service.MultisigServiceInterface |
| 197 | + } |
| 198 | + type args struct { |
| 199 | + ctx context.Context |
| 200 | + req *model.GetMultisignatureInfoRequest |
| 201 | + } |
| 202 | + tests := []struct { |
| 203 | + name string |
| 204 | + fields fields |
| 205 | + args args |
| 206 | + want *model.GetMultisignatureInfoResponse |
| 207 | + wantErr bool |
| 208 | + }{ |
| 209 | + { |
| 210 | + name: "GetMultisignatureInfo:ErrorPageLessThanOne", |
| 211 | + args: args{ |
| 212 | + req: &model.GetMultisignatureInfoRequest{ |
| 213 | + Pagination: &model.Pagination{ |
| 214 | + Page: 0, |
| 215 | + }, |
| 216 | + }, |
| 217 | + }, |
| 218 | + want: nil, |
| 219 | + wantErr: true, |
| 220 | + }, |
| 221 | + { |
| 222 | + name: "GetMultisignatureInfo:ErrorLimitMoreThan30", |
| 223 | + args: args{ |
| 224 | + req: &model.GetMultisignatureInfoRequest{ |
| 225 | + Pagination: &model.Pagination{ |
| 226 | + Page: 31, |
| 227 | + }, |
| 228 | + }, |
| 229 | + }, |
| 230 | + want: nil, |
| 231 | + wantErr: true, |
| 232 | + }, |
| 233 | + { |
| 234 | + name: "GetMultisignatureInfo:Error", |
| 235 | + args: args{ |
| 236 | + req: &model.GetMultisignatureInfoRequest{ |
| 237 | + Pagination: &model.Pagination{ |
| 238 | + Page: 1, |
| 239 | + }, |
| 240 | + }, |
| 241 | + }, |
| 242 | + fields: fields{ |
| 243 | + MultisigService: &mockGetMultisignatureInfoError{}, |
| 244 | + }, |
| 245 | + want: nil, |
| 246 | + wantErr: true, |
| 247 | + }, |
| 248 | + { |
| 249 | + name: "GetMultisignatureInfo:Success", |
| 250 | + args: args{ |
| 251 | + req: &model.GetMultisignatureInfoRequest{ |
| 252 | + Pagination: &model.Pagination{ |
| 253 | + Page: 1, |
| 254 | + }, |
| 255 | + }, |
| 256 | + }, |
| 257 | + fields: fields{ |
| 258 | + MultisigService: &mockGetMultisignatureInfoSuccess{}, |
| 259 | + }, |
| 260 | + want: &model.GetMultisignatureInfoResponse{}, |
| 261 | + wantErr: false, |
| 262 | + }, |
| 263 | + } |
| 264 | + for _, tt := range tests { |
| 265 | + t.Run(tt.name, func(t *testing.T) { |
| 266 | + msh := &MultisigHandler{ |
| 267 | + MultisigService: tt.fields.MultisigService, |
| 268 | + } |
| 269 | + got, err := msh.GetMultisignatureInfo(tt.args.ctx, tt.args.req) |
| 270 | + if (err != nil) != tt.wantErr { |
| 271 | + t.Errorf("MultisigHandler.GetMultisignatureInfo() error = %v, wantErr %v", err, tt.wantErr) |
| 272 | + return |
| 273 | + } |
| 274 | + if !reflect.DeepEqual(got, tt.want) { |
| 275 | + t.Errorf("MultisigHandler.GetMultisignatureInfo() = %v, want %v", got, tt.want) |
| 276 | + } |
| 277 | + }) |
| 278 | + } |
| 279 | +} |
0 commit comments