Skip to content

Commit

Permalink
#26 - testing invites and accept, but failing the latter
Browse files Browse the repository at this point in the history
  • Loading branch information
Sascha Dobbelaere committed Nov 27, 2023
1 parent fbee403 commit 019c9a2
Show file tree
Hide file tree
Showing 4 changed files with 70 additions and 5 deletions.
1 change: 1 addition & 0 deletions OneSila/core/factories/multi_tenant.py
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,7 @@ def run(self):
class AcceptUserInviteFactory:
def __init__(self, user, password, language):
self.user = user

self.password = password
self.language = language

Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
from strawberry import UNSET

from strawberry.relay.utils import from_base64
from strawberry_django.resolvers import django_resolver
from strawberry_django.mutations import resolvers
from strawberry_django.auth.utils import get_current_user
Expand Down Expand Up @@ -90,10 +91,12 @@ class AcceptInvitationMutation(DjangoUpdateMutation):
def update(self, info: Info, instance: models.Model, data: dict[str, Any]):
# Do not optimize anything while retrieving the object to update
with DjangoOptimizerExtension.disabled():
_, user_id = from_base64(data['id'])
user = instance.filter(id=user_id)
fac = AcceptUserInviteFactory(
instance=instance,
password=password,
language=language)
user=user,
password=data['password'],
language=data['language'])
fac.run()

return fac.user
Expand Down
2 changes: 2 additions & 0 deletions OneSila/core/schema/multi_tenant/types/input.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,8 +44,10 @@ class MultiTenantCompanyPartialInput:

@input(MultiTenantUser)
class MultiTenantAcceptInviteInput:
id: auto
username: auto
password: auto
language: auto


@input(MultiTenantUser)
Expand Down
63 changes: 61 additions & 2 deletions OneSila/core/tests/tests_schemas/tests_mutations.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
from django.test import TestCase, TransactionTestCase
from model_bakery import baker

from core.models.multi_tenant import MultiTenantUser
from strawberry.relay import to_base64
from core.models.multi_tenant import MultiTenantUser, MultiTenantCompany
from core.tests.tests_schemas.tests_queries import TransactionTestCaseMixin

from .mutations import REGISTER_USER_MUTATION, LOGIN_MUTATION, LOGOUT_MUTATION, \
Expand Down Expand Up @@ -143,5 +143,64 @@ def test_me(self):
self.assertTrue(resp.data is not None)
self.assertTrue(resp.errors is None)

def test_invite_user(self):
password = '22kk22@ksk!aAD'
company = MultiTenantCompany.objects.create(name='Invitecompany', country="DE")
user = MultiTenantUser(username='use323name@mail.com', language="nl", multi_tenant_company=company)
user.set_password(password)
user.save()

user_id = to_base64("MultiTenantUserType", user.id)

resp = self.stawberry_test_client(
query=LOGIN_MUTATION,
variables={"username": user.username, "password": password}
)

invite_mutation = """
mutation inviteUser($username: String!, $language: String!){
inviteUser(data: {username: $username, language: $language}){
username
isActive
invitationAccepted
}
}
"""

username = "invite@kdka.com"

resp = self.stawberry_test_client(
query=invite_mutation,
variables={'username': username, 'language': 'nl'}
)

self.assertTrue(resp.errors is None)
self.assertFalse(resp.data['inviteUser']['isActive'])
self.assertFalse(resp.data['inviteUser']['invitationAccepted'])

resp = self.stawberry_test_client(
query=LOGOUT_MUTATION,
variables={}
)

accept_mutation = """
mutation acceptUserInvitation($id: GlobalID!, $username: String!, $password: String!){
acceptUserInvitation(data: {id: $id, username: $username, password: $password}){
username
isActive
invitationAccepted
}
}
"""

resp = self.stawberry_test_client(
query=accept_mutation,
variables={'username': username, 'password': "SomePaddk@2k2", "id": user_id}
)

self.assertTrue(resp.errors is None)
self.assertTrue(resp.data['inviteUser']['isActive'])
self.assertTrue(resp.data['inviteUser']['invitationAccepted'])

def test_enable_disable_user(self):
pass

0 comments on commit 019c9a2

Please sign in to comment.