Skip to content

Commit

Permalink
Merge pull request #33 from DEXPRO-Solutions-GmbH/feat/create-record-…
Browse files Browse the repository at this point in the history
…title

Add Title field in RecordRequest to allow creation of record with custom Title
  • Loading branch information
Mirco91 authored Feb 14, 2024
2 parents d3d597a + 52f6520 commit 50bfea1
Show file tree
Hide file tree
Showing 3 changed files with 45 additions and 6 deletions.
13 changes: 13 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,3 +9,16 @@ Since this is an API client for a proprietary software, we have decided to not i
which would allow you to test the client against a running EAS instance.

That is why the CI pipeline skips tests which require a running EAS instance.

If you want to run tests:

1. Have an EAS instance running and accessible from your machine. We recommend Docker.
2. Create a `.env` file in the root of the project with the following content (adjusted to your setup):

```shell
EAS_HOST=localhost:8090

EAS_STORE=store1
EAS_USER=eas_administrator
EAS_PASSWORD=changeme
```
11 changes: 11 additions & 0 deletions r_store_post_record_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ func TestStoreClient_PostRecord(t *testing.T) {
ctx = user.SetOnContext(ctx)

res, err := eastest.DefaultClient().PostRecord(ctx, &easclient.RecordRequest{
Title: "This is my archive file",
Fields: map[string]string{
"Creditor": "DE123456789",
"Debitor": "DE987654321",
Expand All @@ -29,4 +30,14 @@ func TestStoreClient_PostRecord(t *testing.T) {
require.NoError(t, err)
require.NotNil(t, res)
require.NotEqual(t, uuid.Nil, res.ID.Value)

// Retrieve the record
record, err := eastest.DefaultClient().GetRecord(ctx, res.ID.Value)
require.NoError(t, err)

require.Equal(t, res.ID.Value, record.ID)
require.Equal(t, "This is my archive file", record.Title)

require.Equal(t, "DE123456789", record.GetHeaderFieldVal("Creditor"))
require.Equal(t, "DE987654321", record.GetHeaderFieldVal("Debitor"))
}
27 changes: 21 additions & 6 deletions template_record.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,15 +7,29 @@ import (

const recordTemplateStr = `<?xml version="1.0"?>
<records xmlns="http://namespace.otris.de/2010/09/archive/recordExtern">
<record>{{range $key, $value := .Fields}}
<record>
{{- if .Title}}
<title>{{.Title}}</title>
{{end}}
{{- range $key, $value := .Fields}}
<field name="{{$key}}">{{$value}}</field>{{end}}{{range $key, $value := .Attachments}}
<attachment>
<name>{{$value.Name}}</name>
<path>{{$value.Path}}</path>{{if $value.Size}}
<size>{{$value.Size}}</size>{{end}}{{if $value.Register}}
<register>{{$value.Register}}</register>{{end}}{{if $value.Author}}
<author>{{$value.Author}}</author>{{end}}
</attachment>{{end}}
<path>{{$value.Path}}</path>
{{- if $value.Size}}
<size>{{$value.Size}}</size>
{{- end}}
{{- if $value.Register}}
<register>{{$value.Register}}</register>
{{- end}}
{{- if $value.Author}}
<author>{{$value.Author}}</author>
{{- end}}
</attachment>
{{- end}}
</record>
</records>
`
Expand All @@ -31,6 +45,7 @@ func init() {
}

type RecordRequest struct {
Title string
Fields map[string]string
Attachments []*RecordRequestAttachment
}
Expand Down

0 comments on commit 50bfea1

Please sign in to comment.