feat: integrate OA activation workflows and business migration
This commit is contained in:
@@ -0,0 +1,56 @@
|
||||
package business
|
||||
|
||||
import (
|
||||
"context"
|
||||
"testing"
|
||||
)
|
||||
|
||||
type activationPoolFake struct {
|
||||
ActivationPoolRepo
|
||||
options []*ActivationBindingOption
|
||||
requested uint
|
||||
}
|
||||
|
||||
func (r *activationPoolFake) BindingOptions(_ context.Context, id uint) ([]*ActivationBindingOption, error) {
|
||||
r.requested = id
|
||||
return r.options, nil
|
||||
}
|
||||
func (r *activationPoolFake) PoolChannel(context.Context, uint64) (*ActivationPoolChannel, error) {
|
||||
return &ActivationPoolChannel{ID: 10, SourceDB: "lx"}, nil
|
||||
}
|
||||
|
||||
type activationGatewayFake struct {
|
||||
calls int
|
||||
request ActivationApplication
|
||||
}
|
||||
|
||||
func (g *activationGatewayFake) Apply(_ context.Context, a ActivationApplication) error {
|
||||
g.calls++
|
||||
g.request = a
|
||||
return nil
|
||||
}
|
||||
|
||||
func TestActivationApplicationUsesAuthenticatedIdentityAndOwnedBinding(t *testing.T) {
|
||||
accountUC, _ := activationFixture()
|
||||
repo := &activationPoolFake{options: []*ActivationBindingOption{{ID: 9, SourceDB: "lx", Account: "own"}}}
|
||||
gateway := &activationGatewayFake{}
|
||||
uc := NewActivationPoolUsecase(repo, gateway, accountUC.accounts)
|
||||
ctx := accountContext(8, 902)
|
||||
if err := uc.Apply(ctx, 10, 9, "lx"); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if gateway.request.UserID != 8 || repo.requested != 8 || gateway.request.BusierID != 9 {
|
||||
t.Fatal("applicant came from request rather than session")
|
||||
}
|
||||
for _, a := range []ActivationApplication{{PoolID: 10, BusierID: 99, SourceDB: "lx"}, {PoolID: 10, BusierID: 9, SourceDB: "hw"}, {PoolID: 0, BusierID: 9, SourceDB: "lx"}} {
|
||||
if err := uc.Apply(ctx, a.PoolID, a.BusierID, a.SourceDB); err == nil {
|
||||
t.Fatal("unowned application accepted")
|
||||
}
|
||||
}
|
||||
if err := uc.Apply(context.Background(), 10, 9, "lx"); err == nil {
|
||||
t.Fatal("anonymous request accepted")
|
||||
}
|
||||
if gateway.calls != 1 {
|
||||
t.Fatal("invalid requests reached OA")
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user