Conditions | 2 |
Total Lines | 96 |
Code Lines | 67 |
Lines | 0 |
Ratio | 0 % |
Changes | 0 |
Small methods make your code easier to understand, in particular if combined with a good name. Besides, if your method is small, finding a good name is usually much easier.
For example, if you find yourself adding comments to a method's body, this is usually a good sign to extract the commented part to a new method, and use the comment as a starting point when coming up with a good name for this new method.
Commonly applied refactorings include:
If many parameters/temporary variables are present:
1 | package client |
||
129 | func TestSubscriptionsService_Cancel(t *testing.T) { |
||
130 | // Setup |
||
131 | t.Parallel() |
||
132 | |||
133 | // Arrange |
||
134 | server := helpers.MakeTestServer(http.StatusOK, stubs.SubscriptionCancelResponse()) |
||
135 | client := New(WithBaseURL(server.URL)) |
||
136 | |||
137 | // Act |
||
138 | subscription, response, err := client.Subscriptions.Cancel(context.Background(), "1") |
||
139 | |||
140 | // Assert |
||
141 | assert.Nil(t, err) |
||
142 | |||
143 | assert.Equal(t, http.StatusOK, response.HTTPResponse.StatusCode) |
||
144 | assert.Equal(t, stubs.SubscriptionCancelResponse(), *response.Body) |
||
145 | |||
146 | assert.Equal(t, &ApiResponseSubscription{ |
||
147 | Jsonapi: ApiResponseJSONAPI{ |
||
148 | Version: "1.0", |
||
149 | }, |
||
150 | Links: ApiResponseLink{ |
||
151 | Self: "https://api.lemonsqueezy.com/v1/subscriptions/1", |
||
152 | }, |
||
153 | Data: ApiResponseData[Subscription, ApiResponseRelationshipsSubscription]{ |
||
154 | Type: "subscriptions", |
||
155 | ID: "1", |
||
156 | Attributes: Subscription{ |
||
157 | StoreID: 1, |
||
158 | OrderID: 1, |
||
159 | OrderItemID: 1, |
||
160 | ProductID: 1, |
||
161 | VariantID: 1, |
||
162 | ProductName: "Example Product", |
||
163 | VariantName: "Example Variant", |
||
164 | UserName: "Darlene Daugherty", |
||
165 | UserEmail: "[email protected]", |
||
166 | Status: "cancelled", |
||
167 | StatusFormatted: "Cancelled", |
||
168 | Pause: nil, |
||
169 | Cancelled: true, |
||
170 | TrialEndsAt: nil, |
||
171 | BillingAnchor: 12, |
||
172 | Urls: SubscriptionURLs{ |
||
173 | UpdatePaymentMethod: "https://app.lemonsqueezy.com/my-orders/2ba92a4e-a00a-45d2-a128-16856ffa8cdf/subscription/8/update-payment-method?expires=1666869343&signature=9985e3bf9007840aeb3951412be475abc17439c449c1af3e56e08e45e1345413", |
||
174 | }, |
||
175 | RenewsAt: time.Date(2022, time.November, 12, 0, 0, 0, 0, time.UTC), |
||
176 | EndsAt: (func() *time.Time { |
||
177 | val := time.Date(2022, time.November, 12, 0, 0, 0, 0, time.UTC) |
||
178 | return &val |
||
179 | })(), |
||
180 | CreatedAt: time.Date(2021, time.August, 11, 13, 47, 27, 0, time.UTC), |
||
181 | UpdatedAt: time.Date(2021, time.August, 11, 13, 54, 19, 0, time.UTC), |
||
182 | TestMode: false, |
||
183 | }, |
||
184 | Relationships: ApiResponseRelationshipsSubscription{ |
||
185 | Store: ApiResponseLinks{ |
||
186 | Links: ApiResponseLink{ |
||
187 | Related: "https://api.lemonsqueezy.com/v1/subscriptions/1/store", |
||
188 | Self: "https://api.lemonsqueezy.com/v1/subscriptions/1/relationships/store", |
||
189 | }, |
||
190 | }, |
||
191 | Order: ApiResponseLinks{ |
||
192 | Links: ApiResponseLink{ |
||
193 | Related: "https://api.lemonsqueezy.com/v1/subscriptions/1/order", |
||
194 | Self: "https://api.lemonsqueezy.com/v1/subscriptions/1/relationships/order", |
||
195 | }, |
||
196 | }, |
||
197 | OrderItem: ApiResponseLinks{ |
||
198 | Links: ApiResponseLink{ |
||
199 | Related: "https://api.lemonsqueezy.com/v1/subscriptions/1/order-item", |
||
200 | Self: "https://api.lemonsqueezy.com/v1/subscriptions/1/relationships/order-item", |
||
201 | }, |
||
202 | }, |
||
203 | Product: ApiResponseLinks{ |
||
204 | Links: ApiResponseLink{ |
||
205 | Related: "https://api.lemonsqueezy.com/v1/subscriptions/1/product", |
||
206 | Self: "https://api.lemonsqueezy.com/v1/subscriptions/1/relationships/product", |
||
207 | }, |
||
208 | }, |
||
209 | Variant: ApiResponseLinks{ |
||
210 | Links: ApiResponseLink{ |
||
211 | Related: "https://api.lemonsqueezy.com/v1/subscriptions/1/variant", |
||
212 | Self: "https://api.lemonsqueezy.com/v1/subscriptions/1/relationships/variant", |
||
213 | }, |
||
214 | }, |
||
215 | }, |
||
216 | Links: ApiResponseLink{ |
||
217 | Related: "", |
||
218 | Self: "https://api.lemonsqueezy.com/v1/subscriptions/1", |
||
219 | }, |
||
220 | }, |
||
221 | }, subscription) |
||
222 | |||
223 | // Teardown |
||
224 | server.Close() |
||
225 | } |
||
339 |