Skip to content

Commit

Permalink
Bug-Fix SignUp (#2477)
Browse files Browse the repository at this point in the history
* added parameter organizationId

This was causing error since at client side we were not providing the id of organization while registering.

* Fixed tests for missing parameters

* Fixed failing workflow

* Fixed test cases
  • Loading branch information
ArinNigam authored Apr 16, 2024
1 parent 21db262 commit 05b89f4
Show file tree
Hide file tree
Showing 4 changed files with 34 additions and 22 deletions.
4 changes: 3 additions & 1 deletion lib/utils/queries.dart
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ class Queries {
/// * `lastName`: user's data.
/// * `email`: user's data.
/// * `password`: user's data.
/// * `selectedOrganization`: ID of the selected organization.
///
/// **returns**:
/// * `String`: Return the mutation in string type to be passed to graphql client.
Expand All @@ -18,10 +19,11 @@ class Queries {
String lastName,
String email,
String password,
String? selectedOrganization,
) {
return """
mutation{
signUp(data: {firstName: "$firstName", lastName: "$lastName", email: "$email", password: "$password"})
signUp(data: {firstName: "$firstName", lastName: "$lastName", email: "$email", password: "$password", selectedOrganization: "$selectedOrganization"})
{
appUserProfile{
adminFor{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -135,6 +135,7 @@ class SignupDetailsViewModel extends BaseModel {
Encryptor.encryptString(
password.text,
),
selectedOrganization.id,
),
);
navigationService.pop();
Expand Down
9 changes: 7 additions & 2 deletions test/utils_tests/queries_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,13 @@ void main() {
var mutation = false;
expect(mutation, false);

final fnData = Queries()
.registerUser('Ayush', 'Chaudhary', '[email protected]', 'password');
final fnData = Queries().registerUser(
'Ayush',
'Chaudhary',
'[email protected]',
'password',
'orgId123',
);
if (fnData.contains('Ayush')) {
mutation = true;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ class SignUpMock extends StatelessWidget {
}

OrgInfo get org => OrgInfo(
id: '3',
id: '',
name: 'test org 3',
userRegistrationRequired: userRegistrationRequired,
creatorInfo: User(firstName: 'test', lastName: '1'),
Expand Down Expand Up @@ -84,13 +84,13 @@ void main() {
source: QueryResultSource.network,
data: data,
options: QueryOptions(
document: gql(queries.registerUser('', '', '', '')),
document: gql(queries.registerUser('', '', '', '', '')),
),
);
when(graphqlConfig.getToken()).thenAnswer((_) async => true);
when(
databaseFunctions.gqlNonAuthMutation(
queries.registerUser('', '', '', ''),
queries.registerUser('', '', '', '', ''),
),
).thenAnswer((_) async => result);
when(databaseFunctions.gqlAuthMutation(queries.joinOrgById(org.id!)))
Expand All @@ -116,7 +116,7 @@ void main() {
verify(databaseFunctions.gqlAuthMutation(queries.joinOrgById(org.id!)));
verify(
databaseFunctions.gqlNonAuthMutation(
queries.registerUser('', '', '', ''),
queries.registerUser('', '', '', '', ''),
),
);
verify(
Expand All @@ -143,12 +143,12 @@ void main() {
locator.registerSingleton<UserConfig>(MockUserConfig());

final model = SignupDetailsViewModel();

model.selectedOrganization = OrgInfo(id: "");
await tester.pumpWidget(SignUpMock(formKey: model.formKey));

when(
databaseFunctions.gqlNonAuthMutation(
queries.registerUser('', '', '', ''),
queries.registerUser('', '', '', '', ''),
),
).thenAnswer((_) async => null);

Expand Down Expand Up @@ -194,13 +194,13 @@ void main() {
source: QueryResultSource.network,
data: data,
options: QueryOptions(
document: gql(queries.registerUser('', '', '', '')),
document: gql(queries.registerUser('', '', '', '', '')),
),
);
when(graphqlConfig.getToken()).thenAnswer((_) async => false);
when(
databaseFunctions.gqlNonAuthMutation(
queries.registerUser('', '', '', ''),
queries.registerUser('', '', '', '', ''),
),
).thenAnswer((_) async => result);

Expand Down Expand Up @@ -301,13 +301,13 @@ void main() {
source: QueryResultSource.network,
data: data,
options: QueryOptions(
document: gql(queries.registerUser('', '', '', '')),
document: gql(queries.registerUser('', '', '', '', '')),
),
);
when(graphqlConfig.getToken()).thenAnswer((_) async => true);
when(
databaseFunctions.gqlNonAuthMutation(
queries.registerUser('', '', '', ''),
queries.registerUser('', '', '', '', ''),
),
).thenAnswer((_) async => result);
when(
Expand Down Expand Up @@ -340,7 +340,7 @@ void main() {
);
verify(
databaseFunctions.gqlNonAuthMutation(
queries.registerUser('', '', '', ''),
queries.registerUser('', '', '', '', ''),
),
);
verify(
Expand All @@ -364,7 +364,7 @@ void main() {
when(graphqlConfig.getToken()).thenAnswer((_) async => true);
when(
databaseFunctions.gqlNonAuthMutation(
queries.registerUser('', '', '', ''),
queries.registerUser('', '', '', '', ''),
),
).thenThrow(Exception());

Expand All @@ -374,7 +374,7 @@ void main() {

verify(
databaseFunctions.gqlNonAuthMutation(
queries.registerUser('', '', '', ''),
queries.registerUser('', '', '', '', ''),
),
);
verifyNever(
Expand Down Expand Up @@ -416,13 +416,15 @@ void main() {
source: QueryResultSource.network,
data: data,
options: QueryOptions(
document: gql(queries.registerUser('', '', '', '')),
document: gql(
queries.registerUser('', '', '', '', ''),
),
),
);
when(graphqlConfig.getToken()).thenAnswer((_) async => true);
when(
databaseFunctions.gqlNonAuthMutation(
queries.registerUser('', '', '', ''),
queries.registerUser('', '', '', '', ''),
),
).thenAnswer((_) async => result);
when(databaseFunctions.gqlAuthMutation(queries.joinOrgById(org.id!)))
Expand All @@ -435,7 +437,7 @@ void main() {
verify(databaseFunctions.gqlAuthMutation(queries.joinOrgById(org.id!)));
verify(
databaseFunctions.gqlNonAuthMutation(
queries.registerUser('', '', '', ''),
queries.registerUser('', '', '', '', ''),
),
);
verifyNever(
Expand Down Expand Up @@ -478,13 +480,15 @@ void main() {
source: QueryResultSource.network,
data: data,
options: QueryOptions(
document: gql(queries.registerUser('', '', '', '')),
document: gql(
queries.registerUser('', '', '', '', ''),
),
),
);
when(graphqlConfig.getToken()).thenAnswer((_) async => true);
when(
databaseFunctions.gqlNonAuthMutation(
queries.registerUser('', '', '', ''),
queries.registerUser('', '', '', '', ''),
),
).thenAnswer((_) async => result);
when(
Expand All @@ -503,7 +507,7 @@ void main() {
);
verify(
databaseFunctions.gqlNonAuthMutation(
queries.registerUser('', '', '', ''),
queries.registerUser('', '', '', '', ''),
),
);
verifyNever(
Expand Down

0 comments on commit 05b89f4

Please sign in to comment.