Skip to content

Commit 8628af5

Browse files
Merge pull request #68 from CSC207-2022F-UofT/feature-1-and-2-login-and-signup
Feature 1 and 2 login and signup
2 parents 3c6f978 + 17ee1c9 commit 8628af5

File tree

6 files changed

+71
-14
lines changed

6 files changed

+71
-14
lines changed

src/main/java/dataAccess/IUserDataAccess.java

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@
88

99
public interface IUserDataAccess {
1010

11-
1211
/**
1312
* @param username the user's username
1413
* @return the User object who has username
Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
11
title, description, privacy, id, owner, flashcardsIds
2-
test set,for testing study use case,true,0,testUser,0,1,2,3,4,5,6,7,8,9,10,11
3-
empty test set,for testing study use case with empty set,true,1,testUser,
4-
tester, tester thing, true, 0, Steve,
2+
test set,for testing study use case,true,0,Walt,0,1,2,3,4,5,6,7,8,9,10,11
3+
empty test set,for testing study use case with empty set,true,1,Walt,
4+
tester,tester thing,true,3,Steve,
Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,11 @@
11
username,password,isAdmin,flashcardSetIds
2+
Tom,Cruise123,true
23
George,Clooney123,false
4+
Steve,Apple123,false
35
John,Rockefeller123,false
6+
Richard,Virgin123,true
47
testUser,456r2t17yuihjn@,false,0,1
5-
Walt,Disney123,false
8+
Walt,Disney123,false,0,1
9+
Brad,Pitt123,true
610
rObErT,DowneyJr.,true
11+
Ch3is,EVans,true

src/test/java/login_and_sign_up_use_case/userLoginInteractorTest.java

Lines changed: 17 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,9 @@
55
import org.junit.jupiter.api.Test;
66
import static org.junit.Assert.fail;
77
import java.io.IOException;
8+
import java.util.HashMap;
9+
import java.util.Map;
10+
811
import login_and_signup_use_case.login_and_signup_use_case_screens.UserLoginPresenter;
912
import login_and_signup_use_case.UserLoginOutputBoundary;
1013
import login_and_signup_use_case.UserLoginInputBoundary;
@@ -15,12 +18,15 @@
1518
class UserLoginInteractorTest {
1619

1720
// 1) UserLoginInteractorTest and prerequisite objects
18-
21+
IFlashcardDataAccess flashcardGateway = new FlashcardDataAccess(
22+
"src/test/java/login_and_sign_up_use_case/test_data/Flashcards.csv");
23+
IFlashcardSetDataAccess flashcardSetGateway = new FlashcardSetDataAccess(
24+
"src/test/java/login_and_sign_up_use_case/test_data/FlashcardSets.csv");
1925
IUserDataAccess userGateway = new CommonUserDataAccess(
20-
"src/test/java/login_and_sign_up_use_case/test_data/Users.csv");
26+
"src/test/java/login_and_sign_up_use_case/test_data/LoginUsers.csv");
2127

2228

23-
DBGateway gateway = new DBGateway(null, null, userGateway);
29+
DBGateway gateway = new DBGateway(flashcardGateway, flashcardSetGateway, userGateway);
2430

2531
UserLoginInteractorTest() throws IOException {
2632
}
@@ -30,10 +36,12 @@ void login() throws IOException {
3036
UserLoginOutputBoundary presenter = new UserLoginPresenter() {
3137
@Override
3238
public UserLoginResponseModel prepareSuccessView(UserLoginResponseModel user) {
39+
HashMap<Integer, String[]> emptyFlashcardSet = new HashMap();
3340

3441
Assertions.assertEquals("John", user.getSignedInUsername());
3542
Assertions.assertFalse(user.getIsAdmin());
36-
//assertEquals(Map, user.getFlashcardSets());
43+
Assertions.assertTrue(gateway.existsByName("Ch3is"));
44+
Assertions.assertEquals(emptyFlashcardSet, user.getFlashcardSets());
3745
return null;
3846
}
3947

@@ -57,11 +65,15 @@ void login2() throws IOException {
5765
UserLoginOutputBoundary presenter = new UserLoginPresenter() {
5866
@Override
5967
public UserLoginResponseModel prepareSuccessView(UserLoginResponseModel user) {
68+
HashMap<Integer, String[]> emptyFlashcardSet = new HashMap();
69+
Map<Integer, String[]> notEmptyFlashcardSet = user.getFlashcardSets();
6070

6171
Assertions.assertEquals("Walt", user.getSignedInUsername());
6272
Assertions.assertFalse(user.getIsAdmin());
6373
Assertions.assertTrue(!user.getIsAdmin());
64-
//assertEquals({}, user.getFlashcardSets());
74+
Assertions.assertEquals(notEmptyFlashcardSet, user.getFlashcardSets());
75+
System.out.println(user.getFlashcardSets());
76+
Assertions.assertNotEquals(emptyFlashcardSet, user.getFlashcardSets());
6577
return null;
6678
}
6779

@@ -89,7 +101,6 @@ public UserLoginResponseModel prepareSuccessView(UserLoginResponseModel user) {
89101
Assertions.assertEquals("George", user.getSignedInUsername());
90102
Assertions.assertFalse(user.getIsAdmin());
91103
Assertions.assertTrue(!user.getIsAdmin());
92-
//assertEquals({}, user.getFlashcardSets());
93104
return null;
94105
}
95106

@@ -117,7 +128,6 @@ public UserLoginResponseModel prepareSuccessView(UserLoginResponseModel user) {
117128
Assertions.assertEquals("rObErT", user.getSignedInUsername());
118129
Assertions.assertTrue(user.getIsAdmin());
119130
Assertions.assertFalse(!user.getIsAdmin());
120-
//assertEquals({}, user.getFlashcardSets());
121131
return null;
122132
}
123133

src/test/java/login_and_sign_up_use_case/userRegisterInteractorTest.java

Lines changed: 44 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
import org.junit.jupiter.api.Assertions;
1313
import org.junit.jupiter.api.Test;
1414

15+
import java.io.File;
1516
import java.io.IOException;
1617

1718
import static org.junit.Assert.*;
@@ -21,7 +22,9 @@ class UserRegisterInteractorTest {
2122
// 1) UserRegisterInteractor and prerequisite objects
2223

2324
IUserDataAccess userGateway = new CommonUserDataAccess(
24-
"src/test/java/login_and_sign_up_use_case/test_data/Users.csv");
25+
"src/test/java/login_and_sign_up_use_case/test_data/RegistrationUsers.csv");
26+
27+
File file = new File("src/test/java/login_and_sign_up_use_case/test_data/RegistrationUsers.csv");
2528

2629
DBGateway gateway = new DBGateway(null, null, userGateway);
2730

@@ -110,6 +113,7 @@ public UserRegisterResponseModel prepareSuccessView(UserRegisterResponseModel us
110113
Assertions.assertTrue(user.getIsAdmin());
111114
Assertions.assertTrue(gateway.existsByName("Steve"));
112115
Assertions.assertTrue(gateway.existsByName("Richard"));
116+
Assertions.assertTrue(gateway.existsByName("Tom"));
113117
Assertions.assertFalse(gateway.existsByName("Daquan"));
114118
return null;
115119
}
@@ -141,6 +145,8 @@ public UserRegisterResponseModel prepareSuccessView(UserRegisterResponseModel us
141145
Assertions.assertTrue(user.getIsAdmin());
142146
Assertions.assertTrue(gateway.existsByName("Steve"));
143147
Assertions.assertTrue(gateway.existsByName("Richard"));
148+
Assertions.assertTrue(gateway.existsByName("Tom"));
149+
Assertions.assertTrue(gateway.existsByName("Brad"));
144150
Assertions.assertFalse(gateway.existsByName("Daquan"));
145151
return null;
146152
}
@@ -162,4 +168,41 @@ public UserRegisterResponseModel prepareFailView(String error) {
162168
interactor.create(inputData);
163169
}
164170

171+
@Test
172+
void create5() throws IOException {
173+
174+
file.delete();
175+
176+
IUserDataAccess userGateway2 = new InMemoryUser();
177+
178+
DBGateway gateway2 = new DBGateway(null, null, userGateway2);
179+
UserRegisterOutputBoundary presenter = new UserRegisterOutputBoundary() {
180+
@Override
181+
public UserRegisterResponseModel prepareSuccessView(UserRegisterResponseModel user) {
182+
183+
Assertions.assertEquals("Brad", user.getSignedUpUsername());
184+
Assertions.assertTrue(user.getIsAdmin());
185+
// Assertions.assertTrue(gateway.existsByName("Steve"));
186+
Assertions.assertFalse(gateway2.existsByName("Channing"));
187+
Assertions.assertFalse(gateway2.existsByName("Ryan"));
188+
return null;
189+
}
190+
191+
@Override
192+
public UserRegisterResponseModel prepareFailView(String error) {
193+
fail("Use case failure is unexpected.");
194+
return null;
195+
}
196+
};
197+
198+
UserFactory userFactory = new CommonUserFactory();
199+
UserRegisterInputBoundary interactor = new UserRegisterInteractor(
200+
gateway2, presenter, userFactory);
201+
202+
UserRegisterRequestModel inputData = new UserRegisterRequestModel(
203+
"Brad", "Pitt123", "Pitt123", "BuiltDifferent");
204+
205+
interactor.create(inputData);
206+
}
207+
165208
}

src/test/java/studyMode/StudySessionUseCaseUnitTest.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ StudySettingsRequestModel setup(int flashcardSetId, String sortingOrder,
2222
boolean termIsDefault, boolean isReverse) throws IOException {
2323
IFlashcardDataAccess flashcardGateway = new FlashcardDataAccess("src/test/java/studyMode/testData/Flashcards.csv");
2424
IFlashcardSetDataAccess flashcardSetGateway = new FlashcardSetDataAccess("src/test/java/studyMode/testData/FlashcardSets.csv");
25-
IUserDataAccess userGateway = new CommonUserDataAccess("src/test/java/studyMode/testData/Users.csv");
25+
IUserDataAccess userGateway = new CommonUserDataAccess("src/test/java/studyMode/testData/LoginUsers.csv");
2626

2727
DBGateway gateway = new DBGateway(flashcardGateway, flashcardSetGateway, userGateway);
2828

0 commit comments

Comments
 (0)