package serverless

import (
	"testing"

	. "github.com/smartystreets/goconvey/convey"
)

func TestJSONTime(t *testing.T) {
	Convey("TestJSONTime", t, func() {
		Convey("UrlTimeStr should convert to correct string", func() {
			timeStr := "\"2023-06-01 12:34:56.789\""
			jsonTime := JSONTime{}

			err := jsonTime.UnmarshalJSON([]byte(timeStr))
			So(err, ShouldBeNil)

			js, err := jsonTime.MarshalJSON()
			So(err, ShouldBeNil)
			So(string(js), ShouldEqual, timeStr)

			urlTimeStr := jsonTime.UrlTimeStr()
			So(urlTimeStr, ShouldEqual, "2023-06-01%2012:34:56.789")
		})
	})
}
