diff --git a/users/userservice/user-service.js b/users/userservice/user-service.js
index d9de6998..354bcf16 100644
--- a/users/userservice/user-service.js
+++ b/users/userservice/user-service.js
@@ -32,7 +32,7 @@ app.post('/adduser', async (req, res) => {
// Check if required fields are present in the request body
validateRequiredFields(req, ['username', 'password', 'profileImage']);
// Check if the user already exists
- const existingUser = await User.findOne({ username: req.body.username });
+ const existingUser = await User.findOne({ username: req.body.username.toString() });
if (existingUser) {
res.status(400).json({ error: "User already exist" });
return;
diff --git a/webapp/src/test/Login.test.js b/webapp/src/test/Login.test.js
index 2c5021ef..704f46a4 100644
--- a/webapp/src/test/Login.test.js
+++ b/webapp/src/test/Login.test.js
@@ -70,4 +70,37 @@ describe('Login component', () => {
expect(screen.queryByText(/Hello testUser!/i)).toBeNull();
expect(screen.queryByText(/Your account was created on/i)).toBeNull();
});
+ it('should call autologin function when sessionData has token', async () => {
+ const goToMock = jest.fn();
+ const sessionData = { token: 'testToken' };
+
+ render(
+
+
+
+ );
+
+ await waitFor(() => {
+ expect(mockAxios.history.get.length).toBe(1);
+ expect(mockAxios.history.get[0].url).toBe('http://localhost:8000/verify');
+ expect(mockAxios.history.get[0].headers.Authorization).toBe('Bearer testToken');
+ });
+ });
+
+ it('should not call autologin function when sessionData does not have token', async () => {
+ const goToMock = jest.fn();
+ const sessionData = {};
+
+ render(
+
+
+
+ );
+
+ await waitFor(() => {
+ expect(mockAxios.history.get.length).toBe(0);
+ });
+
+ expect(goToMock).not.toHaveBeenCalled();
+ });
});