-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: Month JSON unmarshaling now enforcing year and month only (#906)
- Loading branch information
1 parent
7c5fa15
commit 359307e
Showing
2 changed files
with
31 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
package types_test | ||
|
||
import ( | ||
"encoding/json" | ||
"testing" | ||
|
||
"github.com/envelope-zero/backend/v3/internal/types" | ||
"github.com/stretchr/testify/assert" | ||
) | ||
|
||
func TestMonthUnmarshalJSON(t *testing.T) { | ||
var target struct { | ||
Month types.Month | ||
} | ||
jsonString := []byte(`{ "month": "2024-05-12T17:59:23+02:00" }`) | ||
|
||
err := json.Unmarshal(jsonString, &target) | ||
|
||
assert.Nil(t, err) | ||
assert.Equal(t, types.NewMonth(2024, 5), target.Month) | ||
} |