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

Fixes #1420 Models: Tests for event_model.dart #1452

Conversation

Ayush0Chaudhary
Copy link
Contributor

What kind of change does this PR introduce?
It contains the test for event_model.dart

Issue Number:

Fixes #1420

Did you add tests for your changes?
YES

Summary
It contains the test for event_model.dart

Does this PR introduce a breaking change?
NO

Have you read the contributing guide?
YES

@Ayush0Chaudhary Ayush0Chaudhary force-pushed the Ayush0Chaudhary/event_model_test branch from 2736289 to c5fda49 Compare January 31, 2023 15:38
@palisadoes
Copy link
Contributor

Please fix the failing tests. Merge with upstream.

@Ayush0Chaudhary
Copy link
Contributor Author

@noman2002 @palisadoes please review.

@Ayush0Chaudhary
Copy link
Contributor Author

Please fix the failing tests. Merge with upstream.

merged

@palisadoes palisadoes requested a review from noman2002 January 31, 2023 16:51
@codecov-commenter
Copy link

codecov-commenter commented Jan 31, 2023

Codecov Report

Merging #1452 (5f8e37e) into develop (6fdc10f) will increase coverage by 0.41%.
The diff coverage is n/a.

❗ Current head 5f8e37e differs from pull request most recent head 530f641. Consider uploading reports for the commit 530f641 to get more accurate results

📣 This organization is not using Codecov’s GitHub App Integration. We recommend you install it so Codecov can continue to function properly for your repositories. Learn more

@@             Coverage Diff             @@
##           develop    #1452      +/-   ##
===========================================
+ Coverage    71.85%   72.26%   +0.41%     
===========================================
  Files          146      146              
  Lines         7212     7212              
===========================================
+ Hits          5182     5212      +30     
+ Misses        2030     2000      -30     
Impacted Files Coverage Δ
lib/models/organization/org_info.dart 44.44% <0.00%> (+11.11%) ⬆️
lib/models/events/event_model.dart 100.00% <0.00%> (+27.27%) ⬆️
lib/models/post/post_model.dart 100.00% <0.00%> (+38.63%) ⬆️

📣 We’re building smart automated test selection to slash your CI/CD build times. Learn more

@Ayush0Chaudhary
Copy link
Contributor Author

@noman2002 please review

Copy link
Member

@noman2002 noman2002 left a comment

Choose a reason for hiding this comment

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

Why we need to add userinfo.hive and userinfo.lock

Comment on lines 1 to 25
import 'package:flutter_test/flutter_test.dart';
import 'package:talawa/models/chats/chat_message.dart';
import 'package:talawa/models/chats/chat_user.dart';

final chatUserOne =
ChatUser(firstName: 'Ravidi', id: '1', image: "https://testimg.com");
final chatUserTwo =
ChatUser(firstName: 'Sheikh', id: '2', image: "https://testimg.com");
void main() {
group("Tests for ChatMessage.dart", () {
test('check if ChatMessage JSON serialization works', () {
final message =
ChatMessage('1', chatUserOne, 'Hello, how are you?', chatUserTwo);

final messageJson = message.toJson();

final messageFromJson = ChatMessage.fromJson(messageJson);

expect(messageFromJson.id, message.id);
expect(messageFromJson.sender!.firstName, message.sender!.firstName);
expect(messageFromJson.receiver!.id, message.receiver!.id);
expect(messageFromJson.messageContent, message.messageContent);
});
});
}
Copy link
Member

Choose a reason for hiding this comment

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

Why you have deleted this file?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I think i did it by mistake
looking into it

Copy link
Contributor Author

Choose a reason for hiding this comment

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

their are two folder in model chat and chats

Copy link
Contributor Author

Choose a reason for hiding this comment

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

can we move all file of chat into chats
@noman2002

Copy link
Member

Choose a reason for hiding this comment

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

I am not sure why there are two folders. I guess their must be some purpose for it. Let it be for now.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

ok

@noman2002
Copy link
Member

Why we need to add userinfo.hive and userinfo.lock

what about these files ??

Copy link
Member

@noman2002 noman2002 left a comment

Choose a reason for hiding this comment

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

Restore chat_message_test.dart

@Ayush0Chaudhary
Copy link
Contributor Author

Restore chat_message_test.dart

done

@Ayush0Chaudhary
Copy link
Contributor Author

Ayush0Chaudhary commented Jan 31, 2023

Why we need to add userinfo.hive and userinfo.lock

what about these files ??

it is produced by this test test/model_tests/user/user_info_test.dart (I am not the author)
We should add it in the .gitignore

@noman2002
Copy link
Member

Why we need to add userinfo.hive and userinfo.lock

what about these files ??

it is produced by this test test/model_tests/user/user_info_test.dart (I am not the author) We should add it in the .gitignore

Okay got. I'll update it. No issues.

@palisadoes
Copy link
Contributor

Why we need to add userinfo.hive and userinfo.lock

what about these files ??

it is produced by this test test/model_tests/user/user_info_test.dart (I am not the author) We should add it in the .gitignore

  1. If the test is successful, then it should delete the file. Can you edit it to make sure that happens? It should also be generated in a temporary location outside of the code base. Is that possible?
  2. If it is not possible then the file can remain, but must be deleted and added to .gitignore.

@Ayush0Chaudhary
Copy link
Contributor Author

@noman2002 is the PR okay?

Why we need to add userinfo.hive and userinfo.lock

what about these files ??

it is produced by this test test/model_tests/user/user_info_test.dart (I am not the author) We should add it in the .gitignore

  1. If the test is successful, then it should delete the file. Can you edit it to make sure that happens? It should also be generated in a temporary location outside of the code base. Is that possible?
  2. If it is not possible then the file can remain, but must be deleted and added to .gitignore.

I'll look into 1st option and came back to you

@palisadoes
Copy link
Contributor

Thanks. Many languages have packages that allow you to create temporary files independent of the OS. Many times you can add the .suffix of choice.

@Ayush0Chaudhary
Copy link
Contributor Author

Ayush0Chaudhary commented Jan 31, 2023

Screenshot from 2023-02-01 01-04-22
Added to temporaryPath which contain all the hive files @palisadoes @noman2002

@@ -185,7 +185,7 @@ void main() {

test('Check if Hive storage works', () async {
Hive
..init("./data")
..init("./temporaryPath")
Copy link
Contributor Author

Choose a reason for hiding this comment

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

previously it was storing in seprate folder named data and now it will store it in ./temporaryPath

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Copy link
Contributor

Choose a reason for hiding this comment

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

This won't be a valid path for a Windows based developer. Any other suggestions?

Copy link
Contributor Author

@Ayush0Chaudhary Ayush0Chaudhary Jan 31, 2023

Choose a reason for hiding this comment

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

@palisadoes @noman2002 I checked on my Windows machine and it was working
image

This method of storing hive file is used by other test also
for example

final Directory dir = Directory('temporaryPath');
Hive
..init(dir.path)
..registerAdapter(UserAdapter())
..registerAdapter(OrgInfoAdapter());
await Hive.openBox<User>('currentUser');
await Hive.openBox<OrgInfo>('currentOrg');
await Hive.openBox('url');

and
final Directory dir = Directory('temporaryPath');
Hive
..init(dir.path)
..registerAdapter(UserAdapter())
..registerAdapter(OrgInfoAdapter());
await Hive.openBox<User>('currentUser');
await Hive.openBox<OrgInfo>('currentOrg');
await Hive.openBox('url');

or I am not able to understand what you want to say. We are just making a file named temporaryPath. I think you misunderstood temporaryPath by /temp file provided in linux systems
image

Copy link
Contributor

Choose a reason for hiding this comment

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

OK, so we are using Hive to temporarily store data for testing, but in the lib/ directory. Should we create a test specific const for this for consistency? Like in here https://github.com/PalisadoesFoundation/talawa/tree/develop/test/helpers

Copy link
Contributor Author

@Ayush0Chaudhary Ayush0Chaudhary Feb 1, 2023

Choose a reason for hiding this comment

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

Yes we can do something like this for consistency, maybe write all the hive init in one file and call them according to their requirement, instead of initialising Hive in each test case separately.
It will make our code more DRY.
@palisadoes @noman2002

Copy link
Contributor Author

@Ayush0Chaudhary Ayush0Chaudhary Feb 1, 2023

Choose a reason for hiding this comment

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

if you like this idea, I'll like to complete this. maybe in this PR or or in separate issue

Copy link
Contributor

Choose a reason for hiding this comment

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

Please fix it in this PR

@Ayush0Chaudhary Ayush0Chaudhary force-pushed the Ayush0Chaudhary/event_model_test branch from 865b0ff to 3f0de6f Compare February 1, 2023 12:13
@Ayush0Chaudhary Ayush0Chaudhary force-pushed the Ayush0Chaudhary/event_model_test branch from 3e54b60 to ba8c459 Compare February 1, 2023 12:22
@Ayush0Chaudhary
Copy link
Contributor Author

@noman2002 @palisadoes why is test failing?? Can you help??

@Ayush0Chaudhary
Copy link
Contributor Author

@noman2002 is it a new problem or I did something wrong??
@palisadoes

@noman2002
Copy link
Member

@noman2002 is it a new problem or I did something wrong?? @palisadoes

Codecov problem. It happens.

@palisadoes
Copy link
Contributor

@noman2002 Please review and merge if OK. CodeCov regenerated. I have noticed that when CodeCov fails, you have to delete the previous CodeCov comment an rerun the action.

@Ayush0Chaudhary
Copy link
Contributor Author

@noman2002 please review

@Ayush0Chaudhary
Copy link
Contributor Author

@noman2002 do I need to change something??

@palisadoes palisadoes merged commit ed2925a into PalisadoesFoundation:develop Feb 2, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Models: Tests for event_model.dart
4 participants