Skip to content

Commit

Permalink
init custom domain unit tests.
Browse files Browse the repository at this point in the history
  • Loading branch information
rene00 committed Jan 27, 2021
1 parent 880ded5 commit 5e5a674
Showing 1 changed file with 62 additions and 0 deletions.
62 changes: 62 additions & 0 deletions internal/cli/custom_domains_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
package cli

import (
"bytes"
"io/ioutil"
"testing"

"github.com/auth0/auth0-cli/internal/auth0"
"github.com/auth0/auth0-cli/internal/display"
"github.com/golang/mock/gomock"
"github.com/stretchr/testify/assert"
"gopkg.in/auth0.v5/management"
)

func TestCustomDomainsCmd(t *testing.T) {
t.Run("List", func(t *testing.T) {
ctrl := gomock.NewController(t)
defer ctrl.Finish()
m := auth0.NewMockCustomDomainAPI(ctrl)
m.EXPECT().List().MaxTimes(1).Return([]*management.CustomDomain{{ID: auth0.String("testID"), Domain: auth0.String("testDomain"), Type: auth0.String("testType")}}, nil)
stdout := &bytes.Buffer{}
cli := &cli{
renderer: &display.Renderer{
MessageWriter: ioutil.Discard,
ResultWriter: stdout,
Format: display.OutputFormat("json"),
},
api: &auth0.API{CustomDomain: m},
}

cmd := customDomainsListCmd(cli)
if err := cmd.Execute(); err != nil {
t.Fatal(err)
}

assert.JSONEq(t, `[{"ID": "testID", "Domain": "testDomain", "Type": "testType", "Primary": false, "Status": "", "VerificationMethod": "","Verification": {"Methods": null}}]`, stdout.String())
})

t.Run("Create", func(t *testing.T) {
ctrl := gomock.NewController(t)
defer ctrl.Finish()
m := auth0.NewMockCustomDomainAPI(ctrl)
m.EXPECT().Create(gomock.Any()).MaxTimes(1).Return(nil)
stdout := &bytes.Buffer{}
cli := &cli{
renderer: &display.Renderer{
MessageWriter: ioutil.Discard,
ResultWriter: stdout,
Format: display.OutputFormat("json"),
},
api: &auth0.API{CustomDomain: m},
}

cmd := customDomainsCreateCmd(cli)
cmd.SetArgs([]string{"--domain=testDomain", "--type=testType"})
if err := cmd.Execute(); err != nil {
t.Fatal(err)
}

assert.JSONEq(t, `[{"ID": "", "Domain": "testDomain", "Type": "testType", "Primary": false, "Status": "", "VerificationMethod": "txt","Verification": {"Methods": null}}]`, stdout.String())
})
}

0 comments on commit 5e5a674

Please sign in to comment.