Skip to content

Commit

Permalink
chore: fixing tests (#76)
Browse files Browse the repository at this point in the history
  • Loading branch information
jleon15 authored Feb 12, 2024
1 parent 22d3e35 commit a8e9719
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 101 deletions.
13 changes: 1 addition & 12 deletions tests/api_proxies_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,16 +10,6 @@ func TestProxiesCRUD(t *testing.T) {
// SETUP
apiClient, contextWithAPIKey := testutils.CreateApiAndMgmtContext(t)

reactorFormulaName := "Go Test Reactor Formula"
reactorFormulaCode := "module.exports = function (req) {return {raw: \"Goodbye World\"}}"

createReactorFormulaRequest := *basistheory.NewCreateReactorFormulaRequest("private", reactorFormulaName)
createReactorFormulaRequest.SetCode(reactorFormulaCode)

createdReactorFormula, response, err := apiClient.ReactorFormulasApi.Create(contextWithAPIKey).CreateReactorFormulaRequest(createReactorFormulaRequest).Execute()

testutils.AssertMethodDidNotError(err, response, "ReactorFormulasApi Create", t)

applicationPermissions := []string{"token:create"}
createApplicationRequest := *basistheory.NewCreateApplicationRequest("Go Test App", "private")
createApplicationRequest.SetPermissions(applicationPermissions)
Expand All @@ -30,7 +20,7 @@ func TestProxiesCRUD(t *testing.T) {

reactorName := "Go Test Reactor"
createReactorRequest := *basistheory.NewCreateReactorRequest(reactorName)
createReactorRequest.SetFormula(*createdReactorFormula)
createReactorRequest.SetCode("module.exports = function (req) {return {raw: \"Goodbye World\"}}")
createReactorRequest.SetApplication(*createdApplication)
var createdReactor *basistheory.Reactor
createdReactor, response, err = apiClient.ReactorsApi.Create(contextWithAPIKey).CreateReactorRequest(createReactorRequest).Execute()
Expand Down Expand Up @@ -99,6 +89,5 @@ func TestProxiesCRUD(t *testing.T) {
testutils.AssertNotFound(err, t)

_, _ = apiClient.ReactorsApi.Delete(contextWithAPIKey, createdReactor.GetId()).Execute()
_, _ = apiClient.ReactorFormulasApi.Delete(contextWithAPIKey, createdReactorFormula.GetId()).Execute()
_, _ = apiClient.ApplicationsApi.Delete(contextWithAPIKey, createdApplication.GetId()).Execute()
}
63 changes: 0 additions & 63 deletions tests/api_reactor_formulas_test.go

This file was deleted.

34 changes: 8 additions & 26 deletions tests/api_reactors_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,15 +9,6 @@ import (
func TestReactorCRUD(t *testing.T) {
// SETUP
apiClient, contextWithAPIKey := testutils.CreateApiAndMgmtContext(t)
reactorFormulaName := "Go Test Reactor Formula"
reactorFormulaCode := "module.exports = function (req) {return {raw: \"Goodbye World\"}}"

createReactorFormulaRequest := *basistheory.NewCreateReactorFormulaRequest("private", reactorFormulaName)
createReactorFormulaRequest.SetCode(reactorFormulaCode)

createdReactorFormula, response, err := apiClient.ReactorFormulasApi.Create(contextWithAPIKey).CreateReactorFormulaRequest(createReactorFormulaRequest).Execute()

testutils.AssertMethodDidNotError(err, response, "ReactorFormulasApi Create", t)

applicationPermissions := []string{"token:create"}
createApplicationRequest := *basistheory.NewCreateApplicationRequest("Go Test App", "private")
Expand All @@ -31,41 +22,43 @@ func TestReactorCRUD(t *testing.T) {
reactorName := "Go Test Reactor"

createReactorRequest := *basistheory.NewCreateReactorRequest(reactorName)
createReactorRequest.SetFormula(*createdReactorFormula)
createReactorRequest.SetCode("module.exports = function (req) {return {raw: \"Goodbye World\"}}")
createReactorRequest.SetApplication(*createdApplication)
var createdReactor *basistheory.Reactor
createdReactor, response, err = apiClient.ReactorsApi.Create(contextWithAPIKey).CreateReactorRequest(createReactorRequest).Execute()

testutils.AssertMethodDidNotError(err, response, "ReactorsApi Create", t)
testutils.AssertPropertiesMatch(createdReactor.GetName(), reactorName, t)
testutils.AssertPropertiesMatch(createdReactor.Formula, createdReactorFormula, t, basistheory.NullableString{}, basistheory.NullableTime{})
testutils.AssertPropertiesMatch(createdReactor.GetCode(), createReactorRequest.GetCode(), t)

// GET BY ID
var reactor *basistheory.Reactor
reactor, response, err = apiClient.ReactorsApi.GetById(contextWithAPIKey, createdReactor.GetId()).Execute()

testutils.AssertMethodDidNotError(err, response, "ReactorsApi GetById", t)
testutils.AssertPropertiesMatch(reactor.GetName(), reactorName, t)
testutils.AssertPropertiesMatch(reactor.Formula, createdReactorFormula, t, basistheory.NullableString{}, basistheory.NullableTime{})
testutils.AssertPropertiesMatch(reactor.GetCode(), createReactorRequest.GetCode(), t)

// GET LIST
var reactors *basistheory.ReactorPaginatedList
reactors, response, err = apiClient.ReactorsApi.Get(contextWithAPIKey).Id([]string{createdReactor.GetId()}).Execute()

testutils.AssertMethodDidNotError(err, response, "ReactorsApi sGet", t)
testutils.AssertPropertiesMatch(reactors.Data[0].GetName(), reactorName, t)
testutils.AssertPropertiesMatch(reactors.Data[0].Formula, createdReactorFormula, t, basistheory.NullableString{}, basistheory.NullableTime{})
testutils.AssertPropertiesMatch(reactors.Data[0].GetCode(), createReactorRequest.GetCode(), t)

// UPDATE
updatedReactorName := "Go Test Reactor Update"
updateReactorRequest := *basistheory.NewUpdateReactorRequest(updatedReactorName)
updateReactorRequest.SetConfiguration(map[string]string{})
updateReactorRequest.SetCode("module.exports = function (req) {return {raw: \"Goodbye World\"}}")

var updatedReactor *basistheory.Reactor
updatedReactor, response, err = apiClient.ReactorsApi.Update(contextWithAPIKey, createdReactor.GetId()).UpdateReactorRequest(updateReactorRequest).Execute()
testutils.AssertMethodDidNotError(err, response, "ReactorsApi Update", t)

testutils.AssertPropertiesMatch(updatedReactor.GetName(), updatedReactorName, t)
testutils.AssertPropertiesMatch(updatedReactor.GetCode(), updateReactorRequest.GetCode(), t)

// DELETE
response, err = apiClient.ReactorsApi.Delete(contextWithAPIKey, createdReactor.GetId()).Execute()
Expand All @@ -76,28 +69,18 @@ func TestReactorCRUD(t *testing.T) {

testutils.AssertNotFound(err, t)

_, _ = apiClient.ReactorFormulasApi.Delete(contextWithAPIKey, createdReactorFormula.GetId()).Execute()
_, _ = apiClient.ApplicationsApi.Delete(contextWithAPIKey, createdApplication.GetId()).Execute()
}

func TestReactorReact(t *testing.T) {
apiClient, contextWithAPIKey := testutils.CreateApiAndMgmtContext(t)
reactorFormulaName := "Go Test Reactor Formula"
reactorFormulaCode := "module.exports = function (req) {return {raw: \"Goodbye World\"}}"

createReactorFormulaRequest := *basistheory.NewCreateReactorFormulaRequest("private", reactorFormulaName)
createReactorFormulaRequest.SetCode(reactorFormulaCode)

createdReactorFormula, response, err := apiClient.ReactorFormulasApi.Create(contextWithAPIKey).CreateReactorFormulaRequest(createReactorFormulaRequest).Execute()

testutils.AssertMethodDidNotError(err, response, "ReactorsApi FormulasApi Create", t)

reactorName := "Go Test Reactor"

createReactorRequest := *basistheory.NewCreateReactorRequest(reactorName)
createReactorRequest.SetFormula(*createdReactorFormula)
createReactorRequest.SetCode("module.exports = function (req) {return {raw: \"Goodbye World\"}}")
var createdReactor *basistheory.Reactor
createdReactor, response, err = apiClient.ReactorsApi.Create(contextWithAPIKey).CreateReactorRequest(createReactorRequest).Execute()
createdReactor, response, err := apiClient.ReactorsApi.Create(contextWithAPIKey).CreateReactorRequest(createReactorRequest).Execute()

testutils.AssertMethodDidNotError(err, response, "ReactorsApi Create", t)

Expand All @@ -114,5 +97,4 @@ func TestReactorReact(t *testing.T) {

apiClient, contextWithAPIKey = testutils.CreateApiAndMgmtContext(t)
response, err = apiClient.ReactorsApi.Delete(contextWithAPIKey, createdReactor.GetId()).Execute()
_, _ = apiClient.ReactorFormulasApi.Delete(contextWithAPIKey, createdReactorFormula.GetId()).Execute()
}

0 comments on commit a8e9719

Please sign in to comment.