Skip to content

Commit

Permalink
実装を直してテストを追加
Browse files Browse the repository at this point in the history
  • Loading branch information
azuki774 committed Nov 21, 2023
1 parent 2cf4547 commit f79d6d7
Show file tree
Hide file tree
Showing 3 changed files with 75 additions and 21 deletions.
2 changes: 1 addition & 1 deletion internal/api/v2/service.go
Original file line number Diff line number Diff line change
Expand Up @@ -181,7 +181,7 @@ func (a *APIService) GetYYYYMMRecords(ctx context.Context, yyyymm string, params

// from
for _, r := range recRawExt1 {
if params.CategoryId == nil || (r.CategoryId == *params.CategoryId) {
if params.From == nil || (r.From == *params.From) {
recRawExt2 = append(recRawExt2, r)
}
}
Expand Down
27 changes: 27 additions & 0 deletions internal/api/v2/service_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -369,6 +369,33 @@ func TestAPIService_GetYYYYMMRecords(t *testing.T) {
},
wantErr: false,
},
{
name: "ok(params from)",
fields: fields{
Logger: l,
Repo: &mockRepo{},
},
args: args{
ctx: context.Background(),
yyyymm: "200001",
params: openapi.GetV2RecordYyyymmParams{
From: strPtr("mawinter-web"),
},
},
wantRecs: []openapi.Record{
{
CategoryId: 200,
CategoryName: "cat2",
Datetime: time.Date(2000, 1, 25, 0, 0, 0, 0, jst),
From: "mawinter-web",
Id: 2,
Memo: "",
Price: 2345,
Type: "",
},
},
wantErr: false,
},
{
name: "ok(not found)",
fields: fields{
Expand Down
67 changes: 47 additions & 20 deletions test/e2e.py
Original file line number Diff line number Diff line change
Expand Up @@ -146,6 +146,34 @@
print(response.status_code)
sys.exit(1)

print("# get records with record 200004 from")
url = "http://localhost:8080/v2/record/200004?from=testfrom2"
response = requests.get(url)
if response.status_code == 200:
json_data = response.json()
want = [
{
"category_id": 200,
"category_name": "家賃",
"id": 2,
"datetime": "2000-04-15T00:00:00+09:00",
"from": "testfrom2",
"type": "",
"price": 2000,
"memo": "",
}
]
if want != json_data:
print("[NG] {}".format(url))
print(json_data)
print(want)
sys.exit(1)
print("[OK] {}".format(url))
else:
print("[NG] {}".format(url))
print(response.status_code)
sys.exit(1)

print("# get records with category_id (not found)")
url = "http://localhost:8080/v2/record/200004?category_id=999"
response = requests.get(url)
Expand Down Expand Up @@ -512,10 +540,7 @@
response = requests.get(url)
if response.status_code == 200:
json_data = response.json()
want = {
"yyyymm": "200007",
"status": False
}
want = {"yyyymm": "200007", "status": False}
if want != json_data:
print("[NG] {}".format(url))
print(json_data)
Expand All @@ -538,7 +563,9 @@
want = {
"yyyymm": "200007",
"status": True,
"confirm_datetime": json_data["confirm_datetime"] # confirm_datetime の細かい日付は比較しないようにする
"confirm_datetime": json_data[
"confirm_datetime"
], # confirm_datetime の細かい日付は比較しないようにする
}

if want != json_data:
Expand All @@ -557,7 +584,7 @@
data1 = '{"category_id": 100, "datetime": "20000712", "from": "testfrom1", "type": "S1", "price": 10000, "memo": "fixed"}'
headers = {"Content-Type": "application/json"}
response = requests.post(url, data=data1, headers=headers)
if response.status_code == 400: # Bad Requests because the table is confirmed
if response.status_code == 400: # Bad Requests because the table is confirmed
print("[OK] {}".format(url))
else:
print("[NG] {}".format(url))
Expand Down Expand Up @@ -608,7 +635,7 @@
"id": 8,
"memo": "",
"price": 3000,
"type": ""
"type": "",
},
{
"category_id": 200,
Expand All @@ -618,7 +645,7 @@
"id": 7,
"memo": "",
"price": 2000,
"type": ""
"type": "",
},
{
"category_id": 100,
Expand All @@ -628,8 +655,8 @@
"id": 6,
"memo": "memo",
"price": 1000,
"type": "S1"
}
"type": "S1",
},
]
if want != json_data:
print("[NG] {}".format(url))
Expand All @@ -656,7 +683,7 @@
"id": 8,
"memo": "",
"price": 3000,
"type": ""
"type": "",
}
]
if want != json_data:
Expand Down Expand Up @@ -684,7 +711,7 @@
"id": 8,
"memo": "",
"price": 3000,
"type": ""
"type": "",
},
{
"category_id": 200,
Expand All @@ -694,7 +721,7 @@
"id": 7,
"memo": "",
"price": 2000,
"type": ""
"type": "",
},
{
"category_id": 100,
Expand All @@ -704,7 +731,7 @@
"id": 6,
"memo": "memo",
"price": 1000,
"type": "S1"
"type": "S1",
},
{
"category_id": 200,
Expand All @@ -714,7 +741,7 @@
"id": 5,
"memo": "memo2",
"price": 2000,
"type": ""
"type": "",
},
{
"category_id": 100,
Expand All @@ -724,7 +751,7 @@
"id": 4,
"memo": "memo1",
"price": 1000,
"type": ""
"type": "",
},
{
"category_id": 300,
Expand All @@ -734,7 +761,7 @@
"id": 3,
"memo": "",
"price": 3000,
"type": ""
"type": "",
},
{
"category_id": 200,
Expand All @@ -744,7 +771,7 @@
"id": 2,
"memo": "",
"price": 2000,
"type": ""
"type": "",
},
{
"category_id": 100,
Expand All @@ -754,8 +781,8 @@
"id": 1,
"memo": "memo",
"price": 1000,
"type": "S1"
}
"type": "S1",
},
]
if want != json_data:
print("[NG] {}".format(url))
Expand Down

0 comments on commit f79d6d7

Please sign in to comment.