package ozon import ( "context" "net/http" "testing" core "github.com/diphantxm/ozon-api-client" ) func TestCreateUpdateProformaLink(t *testing.T) { t.Parallel() tests := []struct { statusCode int headers map[string]string params *CreateUpdateProformaLinkParams response string }{ // Test Ok { http.StatusOK, map[string]string{"Client-Id": "my-client-id", "Api-Key": "my-api-key"}, &CreateUpdateProformaLinkParams{ PostingNumber: "33920146-0252-1", URL: "https://cdn.ozone.ru/s3/ozon-disk-api/techdoc/seller-api/earsivfatura_1690960445.pdf", HSCode: "2134322", Date: core.TimeFromString(t, "2006-01-02T15:04:05Z", "2023-08-01T12:08:44.342Z"), Number: "424fdsf234", Price: 234.34, PriceCurrency: InvoiceCurrencyRUB, }, `{ "result": true }`, }, // Test No Client-Id or Api-Key { http.StatusUnauthorized, map[string]string{}, &CreateUpdateProformaLinkParams{}, `{ "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)) ctx, _ := context.WithTimeout(context.Background(), testTimeout) resp, err := c.Invoices().CreateUpdate(ctx, test.params) if err != nil { t.Error(err) continue } compareJsonResponse(t, test.response, &CreateUpdateProformaLinkResponse{}) if resp.StatusCode != test.statusCode { t.Errorf("got wrong status code: got: %d, expected: %d", resp.StatusCode, test.statusCode) } } } func TestGetProformaLink(t *testing.T) { t.Parallel() tests := []struct { statusCode int headers map[string]string params *GetProformaLinkParams response string }{ // Test Ok { http.StatusOK, map[string]string{"Client-Id": "my-client-id", "Api-Key": "my-api-key"}, &GetProformaLinkParams{ PostingNumber: "posting number", }, `{ "result": { "file_url": "string" } }`, }, // Test No Client-Id or Api-Key { http.StatusUnauthorized, map[string]string{}, &GetProformaLinkParams{}, `{ "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)) ctx, _ := context.WithTimeout(context.Background(), testTimeout) resp, err := c.Invoices().Get(ctx, test.params) if err != nil { t.Error(err) continue } compareJsonResponse(t, test.response, &GetProformaLinkResponse{}) if resp.StatusCode != test.statusCode { t.Errorf("got wrong status code: got: %d, expected: %d", resp.StatusCode, test.statusCode) } } } func TestDeleteProformaLink(t *testing.T) { t.Parallel() tests := []struct { statusCode int headers map[string]string params *DeleteProformaLinkParams response string }{ // Test Ok { http.StatusOK, map[string]string{"Client-Id": "my-client-id", "Api-Key": "my-api-key"}, &DeleteProformaLinkParams{ PostingNumber: "posting number", }, `{ "result": true }`, }, // Test No Client-Id or Api-Key { http.StatusUnauthorized, map[string]string{}, &DeleteProformaLinkParams{}, `{ "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)) ctx, _ := context.WithTimeout(context.Background(), testTimeout) resp, err := c.Invoices().Delete(ctx, test.params) if err != nil { t.Error(err) continue } compareJsonResponse(t, test.response, &DeleteProformaLinkResponse{}) if resp.StatusCode != test.statusCode { t.Errorf("got wrong status code: got: %d, expected: %d", resp.StatusCode, test.statusCode) } } }