add method for adding product to promotion

This commit is contained in:
diPhantxm
2023-03-16 19:51:25 +03:00
parent 12773269d4
commit 2c95f2e4c2
3 changed files with 111 additions and 1 deletions

View File

@@ -64,3 +64,59 @@ func TestGetAvailablePromotions(t *testing.T) {
}
}
}
func TestAddToPromotion(t *testing.T) {
tests := []struct {
statusCode int
headers map[string]string
params *AddProductToPromotionParams
response string
}{
// Test Ok
{
http.StatusOK,
map[string]string{"Client-Id": "my-client-id", "Api-Key": "my-api-key"},
&AddProductToPromotionParams{
ActionId: 60564,
Products: []AddProductToPromotionProduct{
{
ProductId: 1389,
ActionPrice: 356,
Stock: 10,
},
},
},
`{
"result": {
"product_ids": [
1389
],
"rejected": []
}
}`,
},
// Test No Client-Id or Api-Key
{
http.StatusUnauthorized,
map[string]string{},
&AddProductToPromotionParams{},
`{
"code": 16,
"message": "Client-Id and Api-Key headers are required"
}`,
},
}
for _, test := range tests {
c := NewMockClient(core.NewMockHttpHandler(test.statusCode, test.response, test.headers))
resp, err := c.Promotions().AddToPromotion(test.params)
if err != nil {
t.Error(err)
}
if resp.StatusCode != test.statusCode {
t.Errorf("got wrong status code: got: %d, expected: %d", resp.StatusCode, test.statusCode)
}
}
}