Skip to content

Commit

Permalink
Update login test
Browse files Browse the repository at this point in the history
  • Loading branch information
YashNathani0708 committed Nov 11, 2024
1 parent 02ba924 commit e235c4a
Show file tree
Hide file tree
Showing 2 changed files with 58 additions and 4 deletions.
60 changes: 57 additions & 3 deletions Test/login.test.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,57 @@
test('Login', () => {
expect(2 + 2).toBe(4);
});

// function login(username, password) {

// return username === 'user' && password === 'pass';
// }

// // Unit test for the login function
// test('Login with valid credentials', () => {
// expect(login('user', 'pass')).toBe(true);
// });

// test('Login with invalid credentials', () => {
// expect(login('user', 'wrongpass')).toBe(false);
// });


// login.test.js
const { initializeApp } = require("firebase/app");
const { getAuth, signInWithEmailAndPassword } = require("firebase/auth");


const firebaseConfig = {
apiKey: "AIzaSyC-GgVnoeRB7KSgRIEBTpyNrtCuUKjk4TA",
authDomain: "soen341-project-group12.firebaseapp.com",
projectId: "soen341-project-group12",
storageBucket: "soen341-project-group12.appspot.com",
messagingSenderId: "551475228011",
appId: "1:551475228011:web:d14120a0b7549888d0f02e",
measurementId: "G-S286NL2V3Z"
};

const app = initializeApp(firebaseConfig);
const auth = getAuth(app);

async function login(email, password) {
try {
const userCredential = await signInWithEmailAndPassword(auth, email, password);
console.log('Login successful:', userCredential.user);
return userCredential.user ? true : false;
} catch (error) {
console.error("Login failed:", error.code, error.message);
return false;
}
}


test('Login with valid credentials', async (done) => {
const isLoggedIn = await login('[email protected]', '123456');
expect(isLoggedIn).toBe(true);
done();
});

test('Login with invalid credentials', async (done) => {
const isLoggedIn = await login('[email protected]', 'wrongpass');
expect(isLoggedIn).toBe(false);
done();
});
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
"build": "vite build",
"lint": "eslint src --ext js,jsx --report-unused-disable-directives --max-warnings 0",
"preview": "vite preview",
"test": "jest"
"test": "jest"
},
"dependencies": {
"firebase": "^10.13.2",
Expand Down

0 comments on commit e235c4a

Please sign in to comment.