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

fx-rolesAndUsers-accessauth #87

Merged
merged 1 commit into from
Jul 5, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
31 changes: 15 additions & 16 deletions __test__/user.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -196,15 +196,6 @@ describe("Testing user Routes", () => {

expect(response.status).toBe(400);
})

test("should return all users in db --> given '/api/v1/users'", async () => {
const spy = jest.spyOn(User, "findAll");
const spy2 = jest.spyOn(userServices, "getAllUsers");
const response = await request(app).get("/api/v1/users");
expect(spy).toHaveBeenCalled();
expect(spy2).toHaveBeenCalled();
}, 20000);

test("Should return status 401 to indicate Unauthorized user", async () => {
const loggedInUser = {
email: userData.email,
Expand Down Expand Up @@ -241,6 +232,19 @@ describe("Testing user Routes", () => {
expect(response.status).toBe(200)
expect(response.body.message).toBe('User verified successfully.')
},60000)

test("should return 200 when all roles are fetched", async () => {
const response = await request(app)
.get("/api/v1/roles").set('Authorization', `Bearer ${adminToken}`);
expect(response.status).toBe(200);
});
test("should return all users in db --> given '/api/v1/users'", async () => {
const spy = jest.spyOn(User, "findAll");
const spy2 = jest.spyOn(userServices, "getAllUsers");
const response = await request(app).get("/api/v1/users").set('Authorization', `Bearer ${adminToken}`);;
expect(spy).toHaveBeenCalled();
expect(spy2).toHaveBeenCalled();
}, 20000);

test("should update dummyseller's role to seller", async () => {
const logDummySeller = await request(app).post("/api/v1/users/login").send({
Expand Down Expand Up @@ -471,13 +475,6 @@ describe("Admin should be able to CRUD roles", () => {
.set("Authorization", "Bearer " + adminToken);
expect(response.status).toBe(404);
})

test("should return 200 when all roles are fetched", async () => {
const response = await request(app)
.get("/api/v1/roles")
expect(response.status).toBe(200);
});

test("should return 200 when a role is updated", async () => {
const response = await request(app)
.patch("/api/v1/roles/" + newRoleId)
Expand Down Expand Up @@ -611,6 +608,8 @@ describe("Verifying user account",()=>{

})



afterAll(async () => {
try {
await sequelize.query('TRUNCATE TABLE profiles, users CASCADE');
Expand Down
2 changes: 1 addition & 1 deletion src/routes/roleRoutes.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import { isPasswordOutOfDate } from '../middlewares/isPasswordOutOfDate';
const RoleRouter = express.Router();

RoleRouter.post('/', isLoggedIn,isPasswordOutOfDate, isAdmin, validateSchema(roleSchema), roleController.createRole);
RoleRouter.get('/',roleController.getRoles);
RoleRouter.get('/',isLoggedIn,isAdmin,roleController.getRoles);
RoleRouter.patch('/:id', isLoggedIn,isPasswordOutOfDate, isAdmin, validateSchema(roleSchema),roleController.updateRole);
RoleRouter.delete('/:id', isLoggedIn,isPasswordOutOfDate, isAdmin, roleController.deleteRole);

Expand Down
2 changes: 1 addition & 1 deletion src/routes/userRoutes.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ import { isPasswordOutOfDate } from "../middlewares/isPasswordOutOfDate";
import { isVerified } from "../middlewares/isVerified";
const userRoutes = Router();

userRoutes.get("/", fetchAllUsers);
userRoutes.get("/",isLoggedIn,isAdmin, fetchAllUsers);
userRoutes.put("/passwordupdate", isLoggedIn, validateSchema(passwordUpdateSchema), updatePassword)
userRoutes.post("/login", emailValidation,validateSchema(logInSchema),isDisabled,isVerified,userLogin);
userRoutes.post("/register", emailValidation, validateSchema(signUpSchema), createUserController);
Expand Down
Loading