Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature/refactor onboarding step #100

Merged
merged 10 commits into from
Jan 30, 2024
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 Dict, Union

from pydantic import BaseModel

class OnboardingSteps(Enum):

class OnboardingStepName(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, 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(exclude_none=True) for step in steps],
miguel-lorenzo marked this conversation as resolved.
Show resolved Hide resolved
}

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(mode="json") for step in steps],
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

just step.model_dump()

}

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, config=None)],
miguel-lorenzo marked this conversation as resolved.
Show resolved Hide resolved
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, config=None)],
miguel-lorenzo marked this conversation as resolved.
Show resolved Hide resolved
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, config=None)],
miguel-lorenzo marked this conversation as resolved.
Show resolved Hide resolved
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, config=None),
miguel-lorenzo marked this conversation as resolved.
Show resolved Hide resolved
OnboardingStep(step=OnboardingStepName.IDCARD, config=None),
],
default=False,
name="alice-flow-test-onboarding-python-updated",
).unwrap_or_return()
Expand Down
Loading