Skip to content

Commit

Permalink
test: resolve regressions
Browse files Browse the repository at this point in the history
  • Loading branch information
aeneasr committed Oct 19, 2021
1 parent a71cadd commit 64850ed
Show file tree
Hide file tree
Showing 15 changed files with 260 additions and 202 deletions.
2 changes: 1 addition & 1 deletion persistence/sql/persister_login.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,9 @@ func (p *Persister) CreateLoginFlow(ctx context.Context, r *login.Flow) error {
}

func (p *Persister) UpdateLoginFlow(ctx context.Context, r *login.Flow) error {
r.EnsureInternalContext()
cp := *r
cp.NID = corp.ContextualizeNID(ctx, p.nid)
cp.EnsureInternalContext()
return p.update(ctx, cp)
}

Expand Down
2 changes: 1 addition & 1 deletion persistence/sql/persister_registration.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,9 @@ func (p *Persister) CreateRegistrationFlow(ctx context.Context, r *registration.
}

func (p *Persister) UpdateRegistrationFlow(ctx context.Context, r *registration.Flow) error {
r.EnsureInternalContext()
cp := *r
cp.NID = corp.ContextualizeNID(ctx, p.nid)
cp.EnsureInternalContext()
return p.update(ctx, cp)
}

Expand Down
2 changes: 1 addition & 1 deletion persistence/sql/persister_settings.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,8 +37,8 @@ func (p *Persister) GetSettingsFlow(ctx context.Context, id uuid.UUID) (*setting
}

func (p *Persister) UpdateSettingsFlow(ctx context.Context, r *settings.Flow) error {
r.EnsureInternalContext()
cp := *r
cp.NID = corp.ContextualizeNID(ctx, p.nid)
cp.EnsureInternalContext()
return p.update(ctx, cp)
}
24 changes: 24 additions & 0 deletions selfservice/flow/login/test/persistence.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package test

import (
"context"
"fmt"
"testing"
"time"

Expand Down Expand Up @@ -111,6 +112,29 @@ func TestFlowPersister(ctx context.Context, p persistence.Persister) func(t *tes
assertx.EqualAsJSON(t, expected.UI, actual.UI)
})

t.Run("case=should create and update and properly deal with internal context", func(t *testing.T) {
for k, tc := range []struct {
in []byte
expect string
}{
{in: []byte("[]"), expect: "{}"},
{expect: "{}"},
{in: []byte("null"), expect: "{}"},
{in: []byte(`{"foo":"bar"}`), expect: `{"foo":"bar"}`},
} {
t.Run(fmt.Sprintf("run=%d", k), func(t *testing.T) {
r := newFlow(t)
r.InternalContext = tc.in
require.NoError(t, p.CreateLoginFlow(ctx, r))
assert.Equal(t, tc.expect, string(r.InternalContext))

r.InternalContext = tc.in
require.NoError(t, p.UpdateLoginFlow(ctx, r))
assert.Equal(t, tc.expect, string(r.InternalContext))
})
}
})

t.Run("case=network", func(t *testing.T) {
id := x.NewUUID()
nid, p := testhelpers.NewNetwork(t, ctx, p)
Expand Down
24 changes: 24 additions & 0 deletions selfservice/flow/registration/test/persistence.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package test

import (
"context"
"fmt"
"testing"
"time"

Expand Down Expand Up @@ -115,6 +116,29 @@ func TestFlowPersister(ctx context.Context, p persistence.Persister) func(t *tes
}, actual.UI.Nodes)
})

t.Run("case=should create and update and properly deal with internal context", func(t *testing.T) {
for k, tc := range []struct {
in []byte
expect string
}{
{in: []byte("[]"), expect: "{}"},
{expect: "{}"},
{in: []byte("null"), expect: "{}"},
{in: []byte(`{"foo":"bar"}`), expect: `{"foo":"bar"}`},
} {
t.Run(fmt.Sprintf("run=%d", k), func(t *testing.T) {
r := newFlow(t)
r.InternalContext = tc.in
require.NoError(t, p.CreateRegistrationFlow(ctx, r))
assert.Equal(t, tc.expect, string(r.InternalContext))

r.InternalContext = tc.in
require.NoError(t, p.UpdateRegistrationFlow(ctx, r))
assert.Equal(t, tc.expect, string(r.InternalContext))
})
}
})

t.Run("case=network", func(t *testing.T) {
id := x.NewUUID()
nid, p := testhelpers.NewNetwork(t, ctx, p)
Expand Down
6 changes: 3 additions & 3 deletions selfservice/flow/settings/test/persistence.go
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ func TestRequestPersister(ctx context.Context, conf *config.Config, p interface
{in: []byte("[]"), expect: "{}"},
{expect: "{}"},
{in: []byte("null"), expect: "{}"},
{in: []byte(`"{"foo":"bar"}"`), expect: `"{"foo":"bar"}"`},
{in: []byte(`{"foo":"bar"}`), expect: `{"foo":"bar"}`},
} {
t.Run(fmt.Sprintf("run=%d", k), func(t *testing.T) {
r := newFlow(t)
Expand Down Expand Up @@ -243,8 +243,8 @@ func TestRequestPersister(ctx context.Context, conf *config.Config, p interface
require.NoError(t, p.GetConnection(ctx).RawQuery("INSERT INTO identities (id, nid, schema_id, traits, created_at, updated_at) VALUES (?, ?, 'default', '{}', ?, ?)", iid2, nid2, time.Now(), time.Now()).Exec())

sid1, sid2 := x.NewUUID(), x.NewUUID()
require.NoError(t, p.GetConnection(ctx).RawQuery("INSERT INTO selfservice_settings_flows (id, nid, identity_id, ui, created_at, updated_at, expires_at, request_url) VALUES (?, ?, ?, '{}', ?, ?, ?, '')", sid1, nid1, iid1, time.Now(), time.Now(), time.Now().Add(time.Hour)).Exec())
require.NoError(t, p.GetConnection(ctx).RawQuery("INSERT INTO selfservice_settings_flows (id, nid, identity_id, ui, created_at, updated_at, expires_at, request_url) VALUES (?, ?, ?, '{}', ?, ?, ?, '')", sid2, nid2, iid2, time.Now(), time.Now(), time.Now().Add(time.Hour)).Exec())
require.NoError(t, p.GetConnection(ctx).RawQuery("INSERT INTO selfservice_settings_flows (id, nid, identity_id, ui, created_at, updated_at, expires_at, request_url, internal_context) VALUES (?, ?, ?, '{}', ?, ?, ?, '', '{}')", sid1, nid1, iid1, time.Now(), time.Now(), time.Now().Add(time.Hour)).Exec())
require.NoError(t, p.GetConnection(ctx).RawQuery("INSERT INTO selfservice_settings_flows (id, nid, identity_id, ui, created_at, updated_at, expires_at, request_url, internal_context) VALUES (?, ?, ?, '{}', ?, ?, ?, '', '{}')", sid2, nid2, iid2, time.Now(), time.Now(), time.Now().Add(time.Hour)).Exec())

_, err := p.GetSettingsFlow(ctx, sid1)
require.NoError(t, err)
Expand Down
145 changes: 145 additions & 0 deletions selfservice/strategy/profile/fixtures/expected.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,145 @@
{
"action": "http://127.0.0.1:57783/self-service/settings?flow=43dadb18-009f-4e1b-80ce-d1c1c31cbec7",
"method": "POST",
"nodes": [
{
"attributes": {
"disabled": false,
"name": "csrf_token",
"required": true,
"type": "hidden",
"value": "YTUycXZiN2ZxZThvbmZmOHg1N3hzd3lyZHFucTVwenY="
},
"group": "default",
"messages": [],
"meta": {},
"type": "input"
},
{
"attributes": {
"disabled": false,
"name": "traits.email",
"type": "text",
"value": "john-browser@doe.com"
},
"group": "profile",
"messages": [],
"meta": {},
"type": "input"
},
{
"attributes": {
"disabled": false,
"name": "method",
"type": "submit",
"value": "profile"
},
"group": "profile",
"messages": [],
"meta": {
"label": {
"id": 1070003,
"text": "Save",
"type": "info"
}
},
"type": "input"
},
{
"attributes": {
"disabled": false,
"name": "traits.stringy",
"type": "text",
"value": "foobar"
},
"group": "profile",
"messages": [],
"meta": {},
"type": "input"
},
{
"attributes": {
"disabled": false,
"name": "traits.numby",
"type": "number",
"value": 2.5
},
"group": "profile",
"messages": [],
"meta": {},
"type": "input"
},
{
"attributes": {
"disabled": false,
"name": "traits.booly",
"type": "checkbox",
"value": false
},
"group": "profile",
"messages": [],
"meta": {},
"type": "input"
},
{
"attributes": {
"disabled": false,
"name": "traits.should_big_number",
"type": "number",
"value": 2048
},
"group": "profile",
"messages": [],
"meta": {},
"type": "input"
},
{
"attributes": {
"disabled": false,
"name": "traits.should_long_string",
"type": "text",
"value": "asdfasdfasdfasdfasfdasdfasdfasdf"
},
"group": "profile",
"messages": [],
"meta": {},
"type": "input"
},
{
"attributes": {
"disabled": false,
"name": "method",
"type": "submit",
"value": "password"
},
"group": "password",
"messages": [],
"meta": {
"label": {
"id": 1070003,
"text": "Save",
"type": "info"
}
},
"type": "input"
},
{
"attributes": {
"disabled": false,
"name": "password",
"required": true,
"type": "password"
},
"group": "password",
"messages": [],
"meta": {
"label": {
"id": 1070001,
"text": "Password",
"type": "info"
}
},
"type": "input"
}
]
}

0 comments on commit 64850ed

Please sign in to comment.