You are an expert in writing code in many different languages. Your goal is to perform code completion for the following code, keeping in mind the rest of the code and the file meta data.
    Metadata details:
    filename: invitations_test.go
    path of file: ./repos/magistrala/invitations/postgres
    
    the code of the file until where you have to start completion: // Copyright (c) Abstract Machines
// SPDX-License-Identifier: Apache-2.0

package postgres_test

import (
	"context"
	"fmt"
	"strings"
	"testing"
	"time"

	"github.com/absmach/magistrala/internal/testsutil"
	"github.com/absmach/magistrala/invitations"
	"github.com/absmach/magistrala/invitations/postgres"
	"github.com/absmach/magistrala/pkg/errors"
	repoerr "github.com/absmach/magistrala/pkg/errors/repository"
	"github.com/stretchr/testify/assert"
	"github.com/stretchr/testify/require"
)

var (
	invalidUUID = strings.Repeat("a", 37)
	validToken  = strings.Repeat("a", 1024)
	relation    = "relation"
)

func TestInvitationCreate(t *testing.T) {
	t.Cleanup(func() {
		_, err := db.Exec("DELETE FROM invitations")
		require.Nil(t, err, fmt.Sprintf("clean invitations unexpected error: %s", err))
	})
	repo := postgres.NewRepository(database)

	domainID := testsutil.GenerateUUID(t)
	userID := testsutil.GenerateUUID(t)

	cases := []struct {
		desc       string
		invitation invitations.Invitation
		err        error
	}{
		{
			desc: "add new invitation successfully",
			invitation: invitations.Invitation{
				InvitedBy: testsutil.GenerateUUID(t),
				UserID:    userID,
				DomainID:  domainID,
				Token:     validToken,
				Relation:  relation,
				CreatedAt: time.Now(),
			},
			err: nil,
		},
		{
			desc: "add new invitation with an confirmed_at date",
			invitation: invitations.Invitation{
				InvitedBy:   testsutil.GenerateUUID(t),
				UserID:      testsutil.GenerateUUID(t),
				DomainID:    testsutil.GenerateUUID(t),
				Token:       validToken,
				Relation:    relat
    
func TestInvitationCreate(t *testing.T) {
	t.Cleanup(func() {
		_, err := db.Exec("DELETE FROM invitations")
		require.Nil(t, err, fmt.Sprintf("clean invitations unexpected error: %s", err))
	})
	repo := postgres.NewRepository(database)

	domainID := testsutil.GenerateUUID(t)
	userID := testsutil.GenerateUUID(t)

	cases := []struct {
		desc       string
		invitation invitations.Invitation
		err        error
	}{
		{
			desc: "add new invitation successfully",
			invitation: invitations.Invitation{
				InvitedBy: testsutil.GenerateUUID(t),
				UserID:    userID,
				DomainID:  domainID,
				Token:     validToken,
				Relation:  relation,
				CreatedAt: time.Now(),
			},
			err: nil,
		},
		{
			desc: "add new invitation with an confirmed_at date",
			invitation: invitations.Invitation{
				InvitedBy:   testsutil.GenerateUUID(t),
				UserID:      testsutil.GenerateUUID(t),
				DomainID:    testsutil.GenerateUUID(t),
				Token:       validToken,
				Relation:    relation,
				CreatedAt:   time.Now(),
				ConfirmedAt: time.Now(),
			},
			err: nil,
		},
		{
			desc: "add invitation with duplicate invitation",
			invitation: invitations.Invitation{
				InvitedBy: testsutil.GenerateUUID(t),
				UserID:    userID,
				DomainID:  domainID,
				Token:     validToken,
				Relation:  relation,
				CreatedAt: time.Now(),
			},
			err: repoerr.ErrConflict,
		},
		{
			desc: "add invitation with invalid invitation invited_by",
			invitation: invitations.Invitation{
				InvitedBy: invalidUUID,
				UserID:    testsutil.GenerateUUID(t),
				DomainID:  testsutil.GenerateUUID(t),
				Token:     validToken,
				Relation:  relation,
				CreatedAt: time.Now(),
			},
			err: repoerr.ErrMalformedEntity,
		},
		{
			desc: "add invitation with invalid invitation relation",
			invitation: invitations.Invitation{
				InvitedBy: testsutil.GenerateUUID(t),
				UserID:    testsutil.GenerateUUID(t),
				DomainID:  testsutil.GenerateUUID(t),
				Token:     validToken,
				Relation:  strings.Repeat("a", 255),
				CreatedAt: time.Now(),
			},
			err: repoerr.ErrMalformedEntity,
		},
		{
			desc: "add invitation with invalid invitation domain",
			invitation: invitations.Invitation{
				InvitedBy: testsutil.GenerateUUID(t),
				UserID:    testsutil.GenerateUUID(t),
				DomainID:  invalidUUID,
				Token:     validToken,
				Relation:  relation,
				CreatedAt: time.Now(),
			},
			err: repoerr.ErrMalformedEntity,
		},
		{
			desc: "add invitation with invalid invitation user id",
			invitation: invitations.Invitation{
				InvitedBy: testsutil.GenerateUUID(t),
				UserID:    invalidUUID,
				DomainID:  testsutil.GenerateUUID(t),
				Token:     validToken,
				Relation:  relation,
				CreatedAt: time.Now(),
			},
			err: repoerr.ErrMalformedEntity,
		},
		{
			desc: "add invitation with empty invitation domain",
			invitation: invitations.Invitation{
				InvitedBy: testsutil.GenerateUUID(t),
				UserID:    testsutil.GenerateUUID(t),
				Token:     validToken,
				Relation:  relation,
				CreatedAt: time.Now(),
			},
			err: nil,
		},
		{
			desc: "add invitation with empty invitation user id",
			invitation: invitations.Invitation{
				InvitedBy: testsutil.GenerateUUID(t),
				DomainID:  testsutil.GenerateUUID(t),
				Token:     validToken,
				Relation:  relation,
				CreatedAt: time.Now(),
			},
			err: nil,
		},
		{
			desc: "add invitation with empty invitation invited_by",
			invitation: invitations.Invitation{
				DomainID:  testsutil.GenerateUUID(t),
				UserID:    testsutil.GenerateUUID(t),
				Token:     validToken,
				Relation:  relation,
				CreatedAt: time.Now(),
			},
			err: nil,
		},
		{
			desc: "add invitation with empty invitation token",
			invitation: invitations.Invitation{
				InvitedBy: testsutil.GenerateUUID(t),
				DomainID:  testsutil.GenerateUUID(t),
				UserID:    testsutil.GenerateUUID(t),
				Relation:  relation,
				CreatedAt: time.Now(),
			},
			err: nil,
		},
	}
	for _, tc := range cases {
		switch err := repo.Create(context.Background(), tc.invitation); {
		case err == nil:
			assert.Nil(t, err, fmt.Sprintf("%s: expected %s got %s\n", tc.desc, tc.err, err))
		default:
			assert.True(t, errors.Contains(err, tc.err), fmt.Sprintf("%s: expected %s got %s\n", tc.desc, tc.err, err))
		}
	}
}