Skip to content

Commit

Permalink
more custom domain tests.
Browse files Browse the repository at this point in the history
  • Loading branch information
rene00 committed Jan 27, 2021
1 parent 5e5a674 commit c57e6cc
Showing 1 changed file with 70 additions and 2 deletions.
72 changes: 70 additions & 2 deletions internal/cli/custom_domains_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -52,11 +52,79 @@ func TestCustomDomainsCmd(t *testing.T) {
}

cmd := customDomainsCreateCmd(cli)
cmd.SetArgs([]string{"--domain=testDomain", "--type=testType"})
cmd.SetArgs([]string{"--domain=testDomain", "--type=testType", "--verification-method=testVerificationMethod"})
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())
assert.JSONEq(t, `[{"ID": "", "Domain": "testDomain", "Type": "testType", "Primary": false, "Status": "", "VerificationMethod": "testVerificationMethod", "Verification": {"Methods": null}}]`, stdout.String())
})

t.Run("Delete", func(t *testing.T) {
ctrl := gomock.NewController(t)
defer ctrl.Finish()
m := auth0.NewMockCustomDomainAPI(ctrl)
m.EXPECT().Delete(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 := customDomainsDeleteCmd(cli)
cmd.SetArgs([]string{"--custom-domain-id=testCustomDomainID"})
if err := cmd.Execute(); err != nil {
t.Fatal(err)
}
})

t.Run("Get", func(t *testing.T) {
ctrl := gomock.NewController(t)
defer ctrl.Finish()
m := auth0.NewMockCustomDomainAPI(ctrl)
m.EXPECT().Read(gomock.Any()).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 := customDomainsGetCmd(cli)
cmd.SetArgs([]string{"--custom-domain-id=testCustomDomainID"})
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("Verify", func(t *testing.T) {
ctrl := gomock.NewController(t)
defer ctrl.Finish()
m := auth0.NewMockCustomDomainAPI(ctrl)
m.EXPECT().Verify(gomock.Any()).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 := customDomainsVerifyCmd(cli)
cmd.SetArgs([]string{"--custom-domain-id=testCustomDomainID"})
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())
})
}

0 comments on commit c57e6cc

Please sign in to comment.