From de51f2ea31e6ecefb67cd3b7b76ebd38b9bb2662 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Pierre=20P=C3=89RONNET?= Date: Wed, 7 Feb 2024 16:12:37 +0100 Subject: [PATCH] fix(share) Add additional fields and a test MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Pierre PÉRONNET --- v1/share.go | 6 ++++-- v1/share_test.go | 34 ++++++++++++++++++++++++++++++++++ 2 files changed, 38 insertions(+), 2 deletions(-) create mode 100644 v1/share_test.go diff --git a/v1/share.go b/v1/share.go index 8ff192e..2bfe240 100644 --- a/v1/share.go +++ b/v1/share.go @@ -28,15 +28,17 @@ type Share struct { RecipientMails []string `json:"recipient_mails"` } +const timeFormat = `2006-01-02T15:04:05Z` + // Share creates a share for a specific time period, with a title and a security code. func (c *Client) CreateShare(ctx context.Context, startDate, endDate time.Time, title, code string) (*Share, error) { body := map[string]interface{}{ - "start_date": startDate, + "start_date": startDate.UTC().Format(timeFormat), "title": title, } if !endDate.IsZero() { - body["end_date"] = endDate + body["end_date"] = endDate.UTC().Format(timeFormat) } if code != "" { diff --git a/v1/share_test.go b/v1/share_test.go new file mode 100644 index 0000000..ab01d51 --- /dev/null +++ b/v1/share_test.go @@ -0,0 +1,34 @@ +package digiposte_test + +import ( + "time" + + "github.com/onsi/ginkgo/v2" + "github.com/onsi/gomega" + + "github.com/holyhope/digiposte-go-sdk/v1" +) + +var _ = ginkgo.Describe("Share", func() { + ginkgo.Context("Authenticated", func() { + ginkgo.Describe("Create share", func() { + var share *digiposte.Share + + ginkgo.AfterEach(func(ctx ginkgo.SpecContext) { + gomega.Expect(digiposteClient.DeleteShare(ctx, share.InternalID)).To(gomega.Succeed()) + }) + + ginkgo.It("should return a valid share", func(ctx ginkgo.SpecContext) { + t := time.Now() + name := ginkgo.CurrentSpecReport().FullText() + + var err error + + share, err = digiposteClient.CreateShare(ctx, t, t.Add(2*time.Minute), name, "a password") + gomega.Expect(err).ToNot(gomega.HaveOccurred()) + gomega.Expect(share).ToNot(gomega.BeNil()) + gomega.Expect(share.InternalID).ToNot(gomega.BeEmpty()) + }) + }) + }) +})