68 lines
1.8 KiB
Go
68 lines
1.8 KiB
Go
|
package cwtch
|
||
|
|
||
|
import (
|
||
|
"cwtch.im/cwtch/model"
|
||
|
"errors"
|
||
|
"fmt"
|
||
|
)
|
||
|
import "github.com/cucumber/godog"
|
||
|
|
||
|
type legacyGroupTest struct {
|
||
|
group *model.Group
|
||
|
invite string
|
||
|
validationError error
|
||
|
}
|
||
|
|
||
|
func (lgt *legacyGroupTest) aGroupOn(server string) error {
|
||
|
var err error
|
||
|
lgt.group, err = model.NewGroup(server)
|
||
|
return err
|
||
|
}
|
||
|
|
||
|
func (lgt *legacyGroupTest) theGroupIDShouldBeCryptographicallyBoundTo(server string) error {
|
||
|
if lgt.group.GroupServer != server {
|
||
|
return errors.New("group server does not match")
|
||
|
}
|
||
|
if lgt.group.CheckGroup() == false {
|
||
|
return errors.New("group failed cryptographic validation")
|
||
|
}
|
||
|
return nil
|
||
|
}
|
||
|
|
||
|
func (lgt *legacyGroupTest) iGenerateAnInvite() error {
|
||
|
var err error
|
||
|
lgt.invite, err = lgt.group.Invite()
|
||
|
return err
|
||
|
}
|
||
|
|
||
|
func (lgt *legacyGroupTest) theInviteShouldValidate() error {
|
||
|
_, err := model.ValidateInvite(lgt.invite)
|
||
|
return err
|
||
|
}
|
||
|
|
||
|
func (lgt *legacyGroupTest) iValidateTheInvite(invite string) error {
|
||
|
_, err := model.ValidateInvite(invite)
|
||
|
lgt.validationError = err
|
||
|
return nil
|
||
|
}
|
||
|
|
||
|
func (lgt *legacyGroupTest) iShouldGetAValidationError(expectedError string) error {
|
||
|
if lgt.validationError == nil || expectedError != lgt.validationError.Error() {
|
||
|
return fmt.Errorf("unexpected validation error: %v", expectedError)
|
||
|
}
|
||
|
return nil
|
||
|
}
|
||
|
|
||
|
func InitializeScenario(ctx *godog.ScenarioContext) {
|
||
|
lgt := legacyGroupTest{}
|
||
|
ctx.Step(`^a group on "([^"]*)"$`, lgt.aGroupOn)
|
||
|
ctx.Step(`^the GroupID should be cryptographically bound to "([^"]*)"$`, lgt.theGroupIDShouldBeCryptographicallyBoundTo)
|
||
|
|
||
|
ctx.Step(`^I generate an invite$`, lgt.iGenerateAnInvite)
|
||
|
ctx.Step(`^the invite should validate$`, lgt.theInviteShouldValidate)
|
||
|
|
||
|
ctx.Step(`^I validate the invite "([^"]*)"$`, lgt.iValidateTheInvite)
|
||
|
ctx.Step(`^I should get a validation error "([^"]*)"$`, lgt.iShouldGetAValidationError)
|
||
|
|
||
|
}
|