Merged in feature/checkbox (pull request #145)
Checkbox Primary Edge Cases * hascheckboxlogic * gen * preppinggen * exploringcheckbox * removeunselected * tests * failingtest * failintests * nomockqueryapi * db * name * nocontainer * deleterow * cnc * extradocsandupdatetextracts * moretables * appndedtables * baseversion
This commit is contained in:
@@ -66,6 +66,82 @@ func TestGetDocumentText(t *testing.T) {
|
||||
_, err := svc.getDocumentText(ctx, pdf)
|
||||
require.EqualError(t, err, "no textract response")
|
||||
})
|
||||
t.Run("merged_cell_table", func(t *testing.T) {
|
||||
t.Parallel()
|
||||
cfg := DocTextConfig{}
|
||||
svc := Service{
|
||||
cfg: &cfg,
|
||||
}
|
||||
mockTextract := textractmock.NewMockTextractClient(t)
|
||||
cfg.TextractClient = mockTextract
|
||||
|
||||
textractBaseOut, pdf, txtFile, close := getFiles(t, "merged_cell_table")
|
||||
defer close()
|
||||
|
||||
textExpectations(t, ctx, mockTextract, pdf, textractBaseOut)
|
||||
|
||||
text, err := svc.getDocumentText(ctx, pdf)
|
||||
require.NoError(t, err)
|
||||
|
||||
assertReaders(t, txtFile, text)
|
||||
})
|
||||
t.Run("table_check", func(t *testing.T) {
|
||||
t.Parallel()
|
||||
cfg := DocTextConfig{}
|
||||
svc := Service{
|
||||
cfg: &cfg,
|
||||
}
|
||||
mockTextract := textractmock.NewMockTextractClient(t)
|
||||
cfg.TextractClient = mockTextract
|
||||
|
||||
textractBaseOut, pdf, txtFile, close := getFiles(t, "table_check")
|
||||
defer close()
|
||||
|
||||
textExpectations(t, ctx, mockTextract, pdf, textractBaseOut)
|
||||
|
||||
text, err := svc.getDocumentText(ctx, pdf)
|
||||
require.NoError(t, err)
|
||||
|
||||
assertReaders(t, txtFile, text)
|
||||
})
|
||||
t.Run("multi_column", func(t *testing.T) {
|
||||
t.Parallel()
|
||||
cfg := DocTextConfig{}
|
||||
svc := Service{
|
||||
cfg: &cfg,
|
||||
}
|
||||
mockTextract := textractmock.NewMockTextractClient(t)
|
||||
cfg.TextractClient = mockTextract
|
||||
|
||||
textractBaseOut, pdf, txtFile, close := getFiles(t, "multi_column")
|
||||
defer close()
|
||||
|
||||
textExpectations(t, ctx, mockTextract, pdf, textractBaseOut)
|
||||
|
||||
text, err := svc.getDocumentText(ctx, pdf)
|
||||
require.NoError(t, err)
|
||||
|
||||
assertReaders(t, txtFile, text)
|
||||
})
|
||||
t.Run("table_check_row", func(t *testing.T) {
|
||||
t.Parallel()
|
||||
cfg := DocTextConfig{}
|
||||
svc := Service{
|
||||
cfg: &cfg,
|
||||
}
|
||||
mockTextract := textractmock.NewMockTextractClient(t)
|
||||
cfg.TextractClient = mockTextract
|
||||
|
||||
textractBaseOut, pdf, txtFile, close := getFiles(t, "table_check_row")
|
||||
defer close()
|
||||
|
||||
textExpectations(t, ctx, mockTextract, pdf, textractBaseOut)
|
||||
|
||||
text, err := svc.getDocumentText(ctx, pdf)
|
||||
require.NoError(t, err)
|
||||
|
||||
assertReaders(t, txtFile, text)
|
||||
})
|
||||
|
||||
t.Run("cnc_01-06", func(t *testing.T) {
|
||||
t.Parallel()
|
||||
@@ -141,25 +217,6 @@ func TestGetDocumentText(t *testing.T) {
|
||||
text, err := svc.getDocumentText(ctx, pdf)
|
||||
require.NoError(t, err)
|
||||
|
||||
assertReaders(t, txtFile, text)
|
||||
})
|
||||
t.Run("merged_cell_table", func(t *testing.T) {
|
||||
t.Parallel()
|
||||
cfg := DocTextConfig{}
|
||||
svc := Service{
|
||||
cfg: &cfg,
|
||||
}
|
||||
mockTextract := textractmock.NewMockTextractClient(t)
|
||||
cfg.TextractClient = mockTextract
|
||||
|
||||
textractBaseOut, pdf, txtFile, close := getFiles(t, "merged_cell_table")
|
||||
defer close()
|
||||
|
||||
textExpectations(t, ctx, mockTextract, pdf, textractBaseOut)
|
||||
|
||||
text, err := svc.getDocumentText(ctx, pdf)
|
||||
require.NoError(t, err)
|
||||
|
||||
assertReaders(t, txtFile, text)
|
||||
})
|
||||
}
|
||||
@@ -208,13 +265,20 @@ func textExpectations(t testing.TB, ctx context.Context, mockTextract *textractm
|
||||
).
|
||||
Return(base, nil)
|
||||
|
||||
table := pageResult["table"]
|
||||
table := pageResult["full_features"]
|
||||
if table != nil {
|
||||
mockTextract.EXPECT().
|
||||
AnalyzeDocument(
|
||||
mock.Anything,
|
||||
mock.MatchedBy(func(in *textract.AnalyzeDocumentInput) bool {
|
||||
return string(in.Document.Bytes) == string(page) && in.FeatureTypes[0] == types.FeatureTypeTables
|
||||
found := false
|
||||
for _, feature := range in.FeatureTypes {
|
||||
if feature == types.FeatureTypeForms || feature == types.FeatureTypeTables {
|
||||
found = true
|
||||
break
|
||||
}
|
||||
}
|
||||
return string(in.Document.Bytes) == string(page) && found
|
||||
}),
|
||||
mock.Anything,
|
||||
).
|
||||
@@ -223,17 +287,21 @@ func textExpectations(t testing.TB, ctx context.Context, mockTextract *textractm
|
||||
}
|
||||
}
|
||||
|
||||
func assertReaderAndString(t testing.TB, expected io.Reader, actual string) {
|
||||
expectedBytes, err := io.ReadAll(expected)
|
||||
require.NoError(t, err)
|
||||
expectedStr := string(expectedBytes)
|
||||
|
||||
if !assert.Equal(t, expectedStr, actual) {
|
||||
diff := cmp.Diff(expectedStr, actual)
|
||||
t.Logf("Detailed diff (-expected +actual):\n%s", diff)
|
||||
}
|
||||
}
|
||||
|
||||
func assertReaders(t testing.TB, expected io.Reader, actual io.Reader) {
|
||||
actualBytes, err := io.ReadAll(actual)
|
||||
require.NoError(t, err)
|
||||
actualStr := string(actualBytes)
|
||||
|
||||
expectedBytes, err := io.ReadAll(expected)
|
||||
require.NoError(t, err)
|
||||
expectedStr := string(expectedBytes)
|
||||
|
||||
if !assert.Equal(t, expectedStr, actualStr) {
|
||||
diff := cmp.Diff(expectedStr, actualStr)
|
||||
t.Logf("Detailed diff (-expected +actual):\n%s", diff)
|
||||
}
|
||||
assertReaderAndString(t, expected, actualStr)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user