Conditions | 1 |
Total Lines | 73 |
Code Lines | 57 |
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 |
||
12 | func TestWebhook(t *testing.T) { |
||
13 | // Setup |
||
14 | t.Parallel() |
||
15 | |||
16 | var request webhookRequest[OrderCreatedWebhookRequestAttributes, OrderCreatedWebhookRequestRelationships] |
||
17 | err := json.Unmarshal(stubs.WebhookRequest(), &request) |
||
18 | assert.Nil(t, err) |
||
19 | |||
20 | assert.Equal(t, webhookRequest[OrderCreatedWebhookRequestAttributes, OrderCreatedWebhookRequestRelationships]{ |
||
21 | Meta: WebhookRequestMeta{ |
||
22 | EventName: "order_created", |
||
23 | TestMode: false, |
||
24 | CustomData: map[string]interface{}(nil), |
||
25 | }, |
||
26 | Data: WebhookRequestData[OrderCreatedWebhookRequestAttributes, OrderCreatedWebhookRequestRelationships]{ |
||
27 | Type: "orders", |
||
28 | ID: "1", |
||
29 | Attributes: OrderCreatedWebhookRequestAttributes{ |
||
30 | StoreID: 1, |
||
31 | Identifier: "636f855c-1fb9-4c07-b75c-3a10afef010a", |
||
32 | OrderNumber: 1, |
||
33 | UserName: "Darlene Daugherty", |
||
34 | UserEmail: "[email protected]", |
||
35 | Currency: "USD", |
||
36 | CurrencyRate: "1.0000", |
||
37 | Subtotal: 999, |
||
38 | DiscountTotal: 0, |
||
39 | Tax: 200, |
||
40 | Total: 1199, |
||
41 | SubtotalUsd: 999, |
||
42 | DiscountTotalUsd: 0, |
||
43 | TaxUsd: 200, |
||
44 | TotalUsd: 1199, |
||
45 | TaxName: "VAT", |
||
46 | TaxRate: "20.00", |
||
47 | Status: "paid", |
||
48 | StatusFormatted: "Paid", |
||
49 | Refunded: false, |
||
50 | RefundedAt: nil, |
||
51 | CreatedAt: time.Date(2021, time.August, 11, 13, 47, 29, 0, time.UTC), |
||
52 | UpdatedAt: time.Date(2021, time.August, 11, 13, 54, 54, 0, time.UTC), |
||
53 | }, |
||
54 | Relationships: OrderCreatedWebhookRequestRelationships{ |
||
55 | Store: ApiResponseLinks{ |
||
56 | Links: ApiResponseLink{ |
||
57 | Related: "https://api.lemonsqueezy.com/v1/orders/1/store", |
||
58 | Self: "https://api.lemonsqueezy.com/v1/orders/1/relationships/store", |
||
59 | }, |
||
60 | }, |
||
61 | OrderItem: ApiResponseLinks{ |
||
62 | Links: ApiResponseLink{ |
||
63 | Related: "https://api.lemonsqueezy.com/v1/orders/1/order-items", |
||
64 | Self: "https://api.lemonsqueezy.com/v1/orders/1/relationships/order-items", |
||
65 | }, |
||
66 | }, |
||
67 | Subscriptions: ApiResponseLinks{ |
||
68 | Links: ApiResponseLink{ |
||
69 | Related: "https://api.lemonsqueezy.com/v1/orders/1/subscriptions", |
||
70 | Self: "https://api.lemonsqueezy.com/v1/orders/1/relationships/subscriptions", |
||
71 | }, |
||
72 | }, |
||
73 | LicenseKeys: ApiResponseLinks{ |
||
74 | Links: ApiResponseLink{ |
||
75 | Related: "https://api.lemonsqueezy.com/v1/orders/1/license-keys", |
||
76 | Self: "https://api.lemonsqueezy.com/v1/orders/1/relationships/license-keys", |
||
77 | }, |
||
78 | }, |
||
79 | }, |
||
80 | Links: ApiResponseLink{ |
||
81 | Self: "https://api.lemonsqueezy.com/v1/orders/1", |
||
82 | }, |
||
83 | }, |
||
84 | }, request) |
||
85 | } |
||
86 |