Skip to content

Commit

Permalink
Merge pull request #7 from holyhope/share/tests
Browse files Browse the repository at this point in the history
fix(share) Add additional fields and a test
  • Loading branch information
holyhope authored Feb 7, 2024
2 parents f6367bd + de51f2e commit b31a40b
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 2 deletions.
6 changes: 4 additions & 2 deletions v1/share.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 != "" {
Expand Down
34 changes: 34 additions & 0 deletions v1/share_test.go
Original file line number Diff line number Diff line change
@@ -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())
})
})
})
})

0 comments on commit b31a40b

Please sign in to comment.