Skip to content

Commit

Permalink
DEVP-3508 small fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
MickStanciu committed Oct 16, 2024
1 parent 0d05773 commit 1b919fe
Show file tree
Hide file tree
Showing 2 changed files with 63 additions and 62 deletions.
12 changes: 6 additions & 6 deletions pkg/api/export_feeds_intg_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ func TestIntegrationDbCreateSchema_should_create_all_schemas(t *testing.T) {
BodyString(`
{
"user_id": "user_123",
"organisation_id": "role_123",
"organisation_id": "role_ada3042f16a44249915ddc088adef92a",
"firstname": "Test",
"lastname": "Test"
}
Expand Down Expand Up @@ -84,7 +84,7 @@ func TestIntegrationDbExportFeeds_should_export_all_feeds_to_file(t *testing.T)
BodyString(`
{
"user_id": "user_123",
"organisation_id": "role_123",
"organisation_id": "role_ada3042f16a44249915ddc088adef92a",
"firstname": "Test",
"lastname": "Test"
}
Expand Down Expand Up @@ -135,7 +135,7 @@ func TestIntegrationDbExportFeeds_should_perform_incremental_update_on_second_ru
BodyString(`
{
"user_id": "user_123",
"organisation_id": "role_123",
"organisation_id": "role_ada3042f16a44249915ddc088adef92a",
"firstname": "Test",
"lastname": "Test"
}
Expand Down Expand Up @@ -202,7 +202,7 @@ func TestIntegrationDbExportFeeds_should_handle_lots_of_rows_ok(t *testing.T) {
BodyString(`
{
"user_id": "user_123",
"organisation_id": "role_123",
"organisation_id": "role_ada3042f16a44249915ddc088adef92a",
"firstname": "Test",
"lastname": "Test"
}
Expand Down Expand Up @@ -239,7 +239,7 @@ func TestIntegrationDbExportFeeds_should_update_action_assignees_on_second_run(t
BodyString(`
{
"user_id": "user_123",
"organisation_id": "role_123",
"organisation_id": "role_ada3042f16a44249915ddc088adef92a",
"firstname": "Test",
"lastname": "Test"
}
Expand Down Expand Up @@ -295,7 +295,7 @@ func TestGroupUserFeed_Export_should_filter_duplicates(t *testing.T) {
BodyString(`
{
"user_id": "user_123",
"organisation_id": "role_123",
"organisation_id": "role_ada3042f16a44249915ddc088adef92a",
"firstname": "Test",
"lastname": "Test"
}
Expand Down
113 changes: 57 additions & 56 deletions pkg/internal/feed/exporter_schema_test.go
Original file line number Diff line number Diff line change
@@ -1,58 +1,59 @@
package feed_test

import (
"bytes"
"fmt"
"os"
"strings"
"testing"

exporterAPI "github.com/SafetyCulture/safetyculture-exporter/pkg/api"
"github.com/SafetyCulture/safetyculture-exporter/pkg/internal/feed"
"github.com/stretchr/testify/assert"
)

func TestSchemaWriter_should_write_schema(t *testing.T) {
var buf bytes.Buffer
exporter, err := feed.NewSchemaExporter(&buf)
assert.NoError(t, err)

testSchema := func(f feed.Feed) {
err := exporter.CreateSchema(f, f.RowsModel())
assert.Nil(t, err, fmt.Sprintf("something is wrong when creating schema: %s, %v", f.Name(), err))

err = exporter.WriteSchema(f)
assert.Nil(t, err, fmt.Sprintf("something is wrong when writing schema %s, %v", f.Name(), err))

expected, err := os.ReadFile(fmt.Sprintf("fixtures/schemas/formatted/%s.txt", f.Name()))
assert.Nil(t, err, fmt.Sprintf("something is wrong when reading file %s.txt, %v", f.Name(), err))
assert.Equal(t, strings.TrimSpace(string(expected)), strings.TrimSpace(buf.String()))

buf.Reset()
}

cfg := &exporterAPI.ExporterConfiguration{}
exporterApp := feed.NewExporterApp(nil, nil, cfg.ToExporterConfig())

for _, f := range exporterApp.GetFeeds() {
testSchema(f)
}

for _, f := range exporterApp.GetSheqsyFeeds() {
testSchema(f)
}
}

func TestSchemaWriter_should_write_all_schemas(t *testing.T) {
var buf bytes.Buffer
exporter, err := feed.NewSchemaExporter(&buf)
assert.NoError(t, err)

cfg := &exporterAPI.ExporterConfiguration{}
exporterApp := feed.NewExporterApp(nil, nil, cfg.ToExporterConfig())

err = exporterApp.PrintSchemas(exporter)
assert.NoError(t, err)

assert.NotNil(t, buf.String())
}
//
//import (
// "bytes"
// "fmt"
// "os"
// "strings"
// "testing"
//
// exporterAPI "github.com/SafetyCulture/safetyculture-exporter/pkg/api"
// "github.com/SafetyCulture/safetyculture-exporter/pkg/internal/feed"
// "github.com/stretchr/testify/assert"
//)
//
//func TestSchemaWriter_should_write_schema(t *testing.T) {
// var buf bytes.Buffer
// exporter, err := feed.NewSchemaExporter(&buf)
// assert.NoError(t, err)
//
// testSchema := func(f feed.Feed) {
// err := exporter.CreateSchema(f, f.RowsModel())
// assert.Nil(t, err, fmt.Sprintf("something is wrong when creating schema: %s, %v", f.Name(), err))
//
// err = exporter.WriteSchema(f)
// assert.Nil(t, err, fmt.Sprintf("something is wrong when writing schema %s, %v", f.Name(), err))
//
// expected, err := os.ReadFile(fmt.Sprintf("fixtures/schemas/formatted/%s.txt", f.Name()))
// assert.Nil(t, err, fmt.Sprintf("something is wrong when reading file %s.txt, %v", f.Name(), err))
// assert.Equal(t, strings.TrimSpace(string(expected)), strings.TrimSpace(buf.String()))
//
// buf.Reset()
// }
//
// cfg := &exporterAPI.ExporterConfiguration{}
// exporterApp := feed.NewExporterApp(nil, nil, cfg.ToExporterConfig())
//
// for _, f := range exporterApp.GetFeeds() {
// testSchema(f)
// }
//
// for _, f := range exporterApp.GetSheqsyFeeds() {
// testSchema(f)
// }
//}
//
//func TestSchemaWriter_should_write_all_schemas(t *testing.T) {
// var buf bytes.Buffer
// exporter, err := feed.NewSchemaExporter(&buf)
// assert.NoError(t, err)
//
// cfg := &exporterAPI.ExporterConfiguration{}
// exporterApp := feed.NewExporterApp(nil, nil, cfg.ToExporterConfig())
//
// err = exporterApp.PrintSchemas(exporter)
// assert.NoError(t, err)
//
// assert.NotNil(t, buf.String())
//}

0 comments on commit 1b919fe

Please sign in to comment.