Skip to content

Commit

Permalink
Merge pull request #100 from alice-biometrics/feature/refactor-onboar…
Browse files Browse the repository at this point in the history
…ding-step

Feature/refactor onboarding step
  • Loading branch information
miguel-lorenzo authored Jan 30, 2024
2 parents 8e5602e + 552bec9 commit ca62504
Show file tree
Hide file tree
Showing 4 changed files with 25 additions and 14 deletions.
10 changes: 9 additions & 1 deletion alice/onboarding/enums/onboarding_steps.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,10 @@
from enum import Enum
from typing import Any, Dict, Union

from pydantic import BaseModel

class OnboardingSteps(Enum):

class OnboardingStepName(str, Enum):
SELFIE = "selfie"
SELFIE_WITH_CHALLENGE = "selfie_with_challenge"
IDCARD = "idcard"
Expand All @@ -11,3 +14,8 @@ class OnboardingSteps(Enum):
PASSPORT = "passport"
OTHER_TRUSTED_DOCUMENT = "otd"
ANY_DOCUMENT = "anydocument"


class OnboardingStep(BaseModel):
step: OnboardingStepName
config: Union[Dict[str, Any], None] = None
6 changes: 3 additions & 3 deletions alice/onboarding/onboarding.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
from alice.onboarding.enums.document_source import DocumentSource
from alice.onboarding.enums.document_type import DocumentType
from alice.onboarding.enums.duplicates_resource_type import DuplicatesResourceType
from alice.onboarding.enums.onboarding_steps import OnboardingSteps
from alice.onboarding.enums.onboarding_steps import OnboardingStep
from alice.onboarding.enums.user_state import UserState
from alice.onboarding.enums.version import Version
from alice.onboarding.models.bounding_box import BoundingBox
Expand Down Expand Up @@ -1818,7 +1818,7 @@ def retrieve_flows(
@early_return
def create_flow(
self,
steps: List[OnboardingSteps],
steps: List[OnboardingStep],
default: bool,
name: str,
id_: Union[str, None] = None,
Expand Down Expand Up @@ -1865,7 +1865,7 @@ def create_flow(
def update_flow(
self,
flow_id: str,
steps: List[OnboardingSteps],
steps: List[OnboardingStep],
default: bool,
name: str,
verbose: bool = False,
Expand Down
10 changes: 5 additions & 5 deletions alice/onboarding/onboarding_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
from alice.onboarding.enums.document_source import DocumentSource
from alice.onboarding.enums.document_type import DocumentType
from alice.onboarding.enums.duplicates_resource_type import DuplicatesResourceType
from alice.onboarding.enums.onboarding_steps import OnboardingSteps
from alice.onboarding.enums.onboarding_steps import OnboardingStep
from alice.onboarding.enums.user_state import UserState
from alice.onboarding.enums.version import Version
from alice.onboarding.models.bounding_box import BoundingBox
Expand Down Expand Up @@ -2093,7 +2093,7 @@ def retrieve_flows(self, verbose: bool = False) -> Result[Response, Error]:
@timeit
def create_flow(
self,
steps: List[OnboardingSteps],
steps: List[OnboardingStep],
default: bool,
name: str,
id_: Union[str, None] = None,
Expand Down Expand Up @@ -2129,7 +2129,7 @@ def create_flow(
data = {
"default": default,
"name": name,
"steps": [step.value for step in steps],
"steps": [step.model_dump() for step in steps],
}

if id_:
Expand All @@ -2153,7 +2153,7 @@ def create_flow(
def update_flow(
self,
flow_id: str,
steps: List[OnboardingSteps],
steps: List[OnboardingStep],
default: bool,
name: str,
verbose: bool = False,
Expand Down Expand Up @@ -2189,7 +2189,7 @@ def update_flow(
"id": flow_id,
"default": default,
"name": name,
"steps": [step.value for step in steps],
"steps": [step.model_dump() for step in steps],
}

try:
Expand Down
13 changes: 8 additions & 5 deletions tests/test_integration_flows.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

from alice import Config, DeviceInfo, Onboarding, UserInfo
from alice.auth.auth_errors import AuthError
from alice.onboarding.enums.onboarding_steps import OnboardingSteps
from alice.onboarding.enums.onboarding_steps import OnboardingStep, OnboardingStepName


@pytest.mark.unit
Expand All @@ -12,7 +12,7 @@ def test_should_return_an_error_when_the_api_key_is_not_configured():
onboarding = Onboarding.from_config(config)

result = onboarding.create_flow(
steps=[OnboardingSteps.SELFIE],
steps=[OnboardingStep(step=OnboardingStepName.SELFIE)],
default=True,
name="test",
)
Expand All @@ -26,7 +26,7 @@ def test_should_timeout_when_time_exceeded(given_valid_api_key):
onboarding = Onboarding.from_config(config)

result = onboarding.create_flow(
steps=[OnboardingSteps.SELFIE],
steps=[OnboardingStep(step=OnboardingStepName.SELFIE)],
default=True,
name="test",
)
Expand All @@ -42,7 +42,7 @@ def do_complete_flow() -> Result[bool, Error]:
onboarding = Onboarding.from_config(config)

flow_id = onboarding.create_flow(
steps=[OnboardingSteps.SELFIE],
steps=[OnboardingStep(step=OnboardingStepName.SELFIE)],
default=False,
name="alice-flow-test-onboarding-python",
).unwrap_or_return()
Expand All @@ -61,7 +61,10 @@ def do_complete_flow() -> Result[bool, Error]:

_ = onboarding.update_flow(
flow_id=flow_id,
steps=[OnboardingSteps.SELFIE, OnboardingSteps.IDCARD],
steps=[
OnboardingStep(step=OnboardingStepName.SELFIE),
OnboardingStep(step=OnboardingStepName.IDCARD),
],
default=False,
name="alice-flow-test-onboarding-python-updated",
).unwrap_or_return()
Expand Down

0 comments on commit ca62504

Please sign in to comment.