-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* [#187584914]added logout feature * [starts #187584914] added logout feature * [finishes#187584914] logout feature * [delivers##187584914] updated readme & swagger.json * [delivers##187584914] updated readme & swagger.json * [deliveres #187584914] logout features completed * [deliveres #187584914] logout features completed * [delivers #187584914] finished logout feature
- Loading branch information
1 parent
869e4e0
commit 589f5f0
Showing
11 changed files
with
354 additions
and
37 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
Believe: Know that the problem you have identified has a solution, and trust that you and your team can build something to address it. | ||
|
||
Understand: Take the time to learn about the experience of the people affected by this problem / who will be using your solution – what does their journey look like? What are their pain points? What factors are affecting how they operate in / engage with the world? | ||
|
||
Invent: Create a Minimum Viable Product or prototype to test out an idea that you have! Be sure to keep in mind how your “invention” will meet your users’ needs. | ||
|
||
Listen: Get feedback from your users on your MVP / prototype and modify it as needed. | ||
|
||
Deliver: Continue to deliver refined versions of your MVP / prototype and improve it over time! | ||
|
||
Password@123 |
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,14 +1,14 @@ | ||
// import { Request } from "express"; | ||
// import multer from "multer"; | ||
// import path from "path"; | ||
import { Request } from "express"; | ||
import multer from "multer"; | ||
import path from "path"; | ||
|
||
// export default multer({ | ||
// storage:multer.diskStorage({}), | ||
// fileFilter:(req:Request,file:Express.Multer.File,cb)=>{ | ||
// const ext = path.extname(file.originalname); | ||
// if(ext!== ".png" && ext!== ".jpg" && ext!== ".jpeg"){ | ||
// return cb(new Error("Only images are allowed")); | ||
// } | ||
// cb(null,true); | ||
// } | ||
// }) | ||
export default multer({ | ||
storage:multer.diskStorage({}), | ||
fileFilter:(req:Request,file:Express.Multer.File,cb)=>{ | ||
const ext = path.extname(file.originalname); | ||
if(ext!== ".png" && ext!== ".jpg" && ext!== ".jpeg"){ | ||
return cb(new Error("Only images are allowed")); | ||
} | ||
cb(null,true); | ||
} | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,18 +1,18 @@ | ||
// /* eslint-disable @typescript-eslint/no-explicit-any */ | ||
// import { v2 as cloudinary } from "cloudinary"; | ||
/* eslint-disable @typescript-eslint/no-explicit-any */ | ||
import { v2 as cloudinary } from "cloudinary"; | ||
|
||
// cloudinary.config({ | ||
// cloud_name: process.env.CLOUD_NAME, | ||
// api_key: process.env.API_KEY, | ||
// api_secret: process.env.API_SECRET | ||
// }); | ||
cloudinary.config({ | ||
cloud_name: process.env.CLOUD_NAME, | ||
api_key: process.env.API_KEY, | ||
api_secret: process.env.API_SECRET | ||
}); | ||
|
||
// export const uploadImages = async (fileToUpload: any): Promise<{ public_id: string; secure_url: string }> => { | ||
// const result = await cloudinary.uploader.upload(fileToUpload.path); | ||
// return { | ||
// public_id: result.public_id, | ||
// secure_url: result.secure_url | ||
// }; | ||
// }; | ||
export const uploadImages = async (fileToUpload: any): Promise<{ public_id: string; secure_url: string }> => { | ||
const result = await cloudinary.uploader.upload(fileToUpload.path); | ||
return { | ||
public_id: result.public_id, | ||
secure_url: result.secure_url | ||
}; | ||
}; | ||
|
||
// export default uploadImages; | ||
export default uploadImages; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,7 @@ | ||
/* eslint-disable @typescript-eslint/no-explicit-any */ | ||
/* eslint-disable @typescript-eslint/no-unused-vars */ | ||
/* eslint-disable comma-dangle */ | ||
/* eslint quotes: "off" */ | ||
import chai, { expect } from "chai"; | ||
import chaiHttp from "chai-http"; | ||
import sinon, { SinonStub } from "sinon"; | ||
|
@@ -9,6 +11,12 @@ import Users from "../../../databases/models/users"; | |
import authRepositories from "../../auth/repository/authRepositories" | ||
import { isUsersExist } from "../../../middlewares/validation"; | ||
import { Op } from "sequelize"; | ||
import path from "path"; | ||
import fs from 'fs' | ||
import uploadImages from "../../../helpers/uploadImage"; | ||
import { v2 as cloudinary } from "cloudinary"; | ||
const imagePath = path.join(__dirname, '../../../__test__/testImage.jpg'); | ||
const imageBuffer = fs.readFileSync(imagePath) | ||
|
||
|
||
chai.use(chaiHttp); | ||
|
@@ -353,4 +361,140 @@ describe("Admin Controllers", () => { | |
done(error) | ||
}); | ||
}); | ||
}); | ||
}); | ||
describe("updateUserProfile", () => { | ||
let profileId :number = null; | ||
let token | ||
|
||
it("should register a new user", (done) => { | ||
router() | ||
.post("/api/auth/register") | ||
.send({ | ||
email: "[email protected]", | ||
password: "userPassword@123" | ||
}) | ||
.end((error, response) => { | ||
expect(response.status).to.equal(httpStatus.CREATED); | ||
expect(response.body).to.be.an("object"); | ||
expect(response.body).to.have.property("data"); | ||
profileId = response.body.data.user.id; | ||
expect(response.body).to.have.property("message", "Account created successfully. Please check email to verify account."); | ||
done(error); | ||
}); | ||
}); | ||
|
||
it("Should be able to login a registered user", (done) => { | ||
router() | ||
.post("/api/auth/login") | ||
.send({ | ||
email: "[email protected]", | ||
password: "userPassword@123" | ||
}) | ||
.end((error, response) => { | ||
expect(response.status).to.equal(httpStatus.OK); | ||
expect(response.body).to.be.a("object"); | ||
expect(response.body).to.have.property("data"); | ||
expect(response.body.message).to.be.a("string"); | ||
expect(response.body.data).to.have.property("token"); | ||
token = response.body.data.token; | ||
done(error); | ||
}); | ||
}); | ||
|
||
|
||
it("Should be able to get", (done) => { | ||
router() | ||
.get(`/api/user/user-get-profile/${profileId}`) | ||
.end((error, response) => { | ||
expect(response).to.have.status(200); | ||
expect(response.body).to.be.a("object"); | ||
done(error); | ||
}); | ||
}); | ||
|
||
it("should update profile ", (done) => { | ||
router().put(`/api/user/user-update-profile/${profileId}`) | ||
.set("Authorization", `Bearer ${token}`) | ||
.field('firstName', 'MANISHIMWE') | ||
.field('lastName', 'Salton Joseph') | ||
.field('phone', '787312593') | ||
.field('gender', 'male') | ||
.field('birthDate', '1943-02-04') | ||
.field('language', 'english') | ||
.field('currency', 'USD') | ||
.attach("profilePicture",imageBuffer,'testImage.jpg') | ||
.end((error, response) => { | ||
|
||
expect(response.status).to.equal(200); | ||
done(error); | ||
}); | ||
}); | ||
it("should return error when user id is invalid", (done) => { | ||
router().put("/api/user/user-update-profile/-1") | ||
.set("Authorization", `Bearer ${token}`) | ||
.send({ | ||
"firstName": "MANISHIMWE", | ||
"lastName": "Salton Joseph", | ||
"phone": "787312593", | ||
"gender": "male", | ||
"birthDate": "1943-02-04T00:00:00.000Z", | ||
"language": "english", | ||
"currency": "USD" | ||
}).end((error, response) => { | ||
|
||
expect(response.status).to.equal(500); | ||
done(error); | ||
}); | ||
}); | ||
|
||
|
||
describe('uploadImages', () => { | ||
let uploadStub: sinon.SinonStub; | ||
|
||
beforeEach(() => { | ||
uploadStub = sinon.stub(cloudinary.uploader, 'upload'); | ||
}); | ||
|
||
afterEach(() => { | ||
uploadStub.restore(); | ||
}); | ||
|
||
it('should upload an image and return the public_id and secure_url', async () => { | ||
const fileToUpload = { path: 'path/to/file.jpg' }; | ||
const mockResult = { | ||
public_id: 'mock_public_id', | ||
secure_url: 'https://mock_secure_url.com', | ||
}; | ||
|
||
uploadStub.resolves(mockResult); | ||
|
||
const result = await uploadImages(fileToUpload); | ||
|
||
expect(uploadStub.calledOnceWith(fileToUpload.path)).to.be.true; | ||
expect(result).to.deep.equal(mockResult); | ||
}); | ||
|
||
it('should handle errors from the upload process', async () => { | ||
const fileToUpload = { path: 'path/to/file.jpg' }; | ||
const mockError = new Error('Upload failed'); | ||
|
||
uploadStub.rejects(mockError); | ||
|
||
try { | ||
await uploadImages(fileToUpload); | ||
expect.fail('Expected error was not thrown'); | ||
} catch (error) { | ||
expect(error).to.be.an('error'); | ||
expect(error.message).to.equal('Upload failed'); | ||
} | ||
}); | ||
|
||
|
||
after(async () => { | ||
await Users.destroy({ | ||
where: {} | ||
}) | ||
}); | ||
|
||
}); | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.