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

Feat/user #175

Merged
merged 4 commits into from
Jun 27, 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
3 changes: 2 additions & 1 deletion controllers/airline.js
Original file line number Diff line number Diff line change
Expand Up @@ -80,14 +80,15 @@ const createNewAirline = async (req, res, next) => {
file
? (imageUrl = await uploadFile(file))
: (imageUrl = "https://placehold.co/600x400");
console.log(imageUrl);

const newAirline = await prisma.airline.create({
data: {
id: randomUUID(),
name,
code,
terminal,
image: imageUrl,
image: imageUrl
},
});

Expand Down
12 changes: 7 additions & 5 deletions controllers/user.js
Original file line number Diff line number Diff line change
Expand Up @@ -101,14 +101,14 @@ const getUserById = async (req, res, next) => {

const createUser = async (req, res, next) => {
try {
const data = req.body;
const { name, phoneNumber, familyName, role } = req.body;
const newUser = await prisma.user.create({
data: {
id: randomUUID(),
name: data.name,
phoneNumber: data.phoneNumber,
familyName: data.familyName,
role: data.role || "BUYER", // Default value for role
name: name,
phoneNumber: phoneNumber,
familyName: familyName,
role: role || "BUYER", // Default value for role
},
});

Expand All @@ -121,6 +121,7 @@ const createUser = async (req, res, next) => {
phoneNumber: newUser.phoneNumber,
familyName: newUser.familyName,
role: newUser.role,
isVerified: true,
},
});
} catch (err) {
Expand Down Expand Up @@ -170,6 +171,7 @@ const updateUser = async (req, res, next) => {
phoneNumber: updatedUser.phoneNumber,
familyName: updatedUser.familyName,
role: updatedUser.role,
isVerified: true,
},
});
} catch (error) {
Expand Down
2 changes: 1 addition & 1 deletion routes/user.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ const {

router
.route("/")
.get(authentication, checkRole(["ADMIN"]), userController.getAllUsers, )
.get(authentication, checkRole(["ADMIN"]), userController.getAllUsers,)
.post(authentication, checkRole(["ADMIN"]), validator(userCreateSchema), userController.createUser);
router
.route("/:id")
Expand Down
78 changes: 78 additions & 0 deletions test/integration1/airline.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,78 @@
require("dotenv").config();

const request = require("supertest");

describe("Airline Integration Test", () => {
let token;
const baseUrl = "http://localhost:2000";
beforeAll(async () => {
const response = await request(baseUrl)
.post("/api/v1/auth/login")
.send({
email: "[email protected]",
password: "password",
});
token = response.body._token;
console.log(`Bearer ${token}`);
});

describe("getAllAirline", () => {
it("success", async () => {
const response = await request(baseUrl)
.get("/api/v1/airlines/")
.set("Authorization", `Bearer ${token}`);
expect(response.statusCode).toBe(200);
});
});

describe("createNewAirline", () => {
it("success", async () => {
const response = await request(baseUrl)
.post("/api/v1/airlines/").send(
{
"name": "Graff Zeppeline",
"code": "GR",
"terminal": "Kedatangan 1"
}
)
.set("Authorization", `Bearer ${token}`);
expect(response.statusCode).toBe(201);
});
});

describe("getAirlineById", () => {
it("success", async () => {
const response = await request(baseUrl)
.get("/api/v1/airlines/10692c9d-522b-42fd-b9a9-90ce1985382e")
.set("Authorization", `Bearer ${token}`);
expect(response.statusCode).toBe(200);
});
});

describe("updateAirline", () => {
it("success", async () => {
const response = await request(baseUrl)
.put("/api/v1/airlines/46a9e70b-06c5-4c8b-9aec-5240b1dae174").send(
{
"name": "Graff Zeppeline",
"code": "GZ",
"terminal": "Kedatangan 1"
}
)
.set("Authorization", `Bearer ${token}`);
expect(response.statusCode).toBe(201);
});
});

// describe("deleteAirline", () => {
// it("success", async () => {
// const response = await request(baseUrl)
// .put("/api/v1/airlines/id")
// .set("Authorization", `Bearer ${token}`);
// expect(response.statusCode).toBe(200);
// });
// });



});
76 changes: 76 additions & 0 deletions test/integration1/airports.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
require("dotenv").config();

const request = require("supertest");

describe("Airports Integration Test", () => {
let token;
const baseUrl = "http://localhost:2000";
beforeAll(async () => {
const response = await request(baseUrl)
.post("/api/v1/auth/login")
.send({
email: "[email protected]",
password: "password",
});
token = response.body._token;
console.log(`Bearer ${token}`);
});

describe("getAllAirports", () => {
it("success", async () => {
const response = await request(baseUrl)
.get("/api/v1/airports/")
.set("Authorization", `Bearer ${token}`);
expect(response.statusCode).toBe(200);
});
});

describe("createNewAirport", () => {
it("success", async () => {
const response = await request(baseUrl)
.post("/api/v1/airports/").send(
{
"name": "Juanda International Airport",
"code": "GZZ",
"country": "jepang",
"city": "tokyo",
"continent": "asia"
}
)
.set("Authorization", `Bearer ${token}`);
expect(response.statusCode).toBe(201);
});
});

describe("getAirportById", () => {
it("success", async () => {
const response = await request(baseUrl)
.get("/api/v1/airports/clxvwmyua00044swk81srzfyh")
.set("Authorization", `Bearer ${token}`);
expect(response.statusCode).toBe(200);
});
});

describe("updateAirport", () => {
it("success", async () => {
const response = await request(baseUrl)
.put("/api/v1/airports/6f690dee-da65-429d-a0f8-67ed5eca86ff").send(
{
"name": "Jokowi International Airport",
}
)
.set("Authorization", `Bearer ${token}`);
expect(response.statusCode).toBe(201);
});
});

// describe("deleteAirport", () => {
// it("success", async () => {
// const response = await request(baseUrl)
// .put("/api/v1/airports/id")
// .set("Authorization", `Bearer ${token}`);
// expect(response.statusCode).toBe(200);
// });
// });

});
63 changes: 63 additions & 0 deletions test/integration1/transaction.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
require("dotenv").config();

const request = require("supertest");

describe("Transaction Integration Test", () => {
let token;
const baseUrl = "https://backend-skyfly-c1.vercel.app";
beforeAll(async () => {
const response = await request(baseUrl)
.post("/api/v1/auth/login")
.send({
email: "[email protected]",
password: "password",
});
token = response.body._token;
console.log(`Bearer ${token}`);
});

describe("getAllTransactionByUserLoggedIn", () => {
it("success", async () => {
const response = await request(baseUrl)
.get("/api/v1/transactions/")
.set("Authorization", `Bearer ${token}`);
expect(response.statusCode).toBe(200);
});
});

// describe("getTransactionById", () => {
// it("success", async () => {
// const response = await request(baseUrl)
// .get("/api/v1/transactions/clxts6a8j0002947lzd5ll8ap")
// .set("Authorization", `Bearer ${token}`);
// expect(response.statusCode).toBe(200);
// });
// });

// describe("getTransaction", () => {
// it("success", async () => {
// const response = await request(baseUrl)
// .get("/api/v1/transactions/status/2ecaed1c-bfb9-4937-a151-7e16634c7385")
// .set("Authorization", `Bearer ${token}`);
// expect(response.statusCode).toBe(200);
// });
// });

// describe("getTransaction", () => {
// it("success", async () => {
// const response = await request(baseUrl)
// .get("/api/v1/transactions/status/2ecaed1c-bfb9-4937-a151-7e16634c7385")
// .set("Authorization", `Bearer ${token}`);
// expect(response.statusCode).toBe(200);
// });
// });

// describe("updateTransaction", () => {
// it("success", async () => {
// const response = await request(baseUrl)
// .post("/api/v1/transactions/payment")
// .set("Authorization", `Bearer ${token}`);
// expect(response.statusCode).toBe(200);
// });
// });
});
Original file line number Diff line number Diff line change
Expand Up @@ -2,62 +2,76 @@ require("dotenv").config();

const request = require("supertest");

describe("Transaction Integration Test", () => {
describe("User Integration Test", () => {
let token;
const baseUrl = "https://backend-skyfly-c1.vercel.app";
const baseUrl = "http://localhost:2000";
beforeAll(async () => {
const response = await request(baseUrl)
.post("/api/v1/auth/login")
.send({
email: "faris@test.com",
email: "miminc1@test.com",
password: "password",
});
token = response.body._token;
console.log(`Bearer ${token}`);
});

describe("getAllTransactionByUserLoggedIn", () => {
describe("getAllUsers", () => {
it("success", async () => {
const response = await request(baseUrl)
.get("/api/v1/transactions/")
.get("/api/v1/users/")
.set("Authorization", `Bearer ${token}`);
expect(response.statusCode).toBe(200);
});
});

describe("getTransactionById", () => {
describe("createUser", () => {
it("success", async () => {
const response = await request(baseUrl)
.get("/api/v1/transactions/clxts6a8j0002947lzd5ll8ap")
.post("/api/v1/users/").send(
{
"name": "padadang",
"phoneNumber": "0821823476",
"familyName": "dudung"
}
)
.set("Authorization", `Bearer ${token}`);
expect(response.statusCode).toBe(200);
expect(response.statusCode).toBe(201);
});
});

describe("getTransaction", () => {
describe("getUserById", () => {
it("success", async () => {
const response = await request(baseUrl)
.get("/api/v1/transactions/status/2ecaed1c-bfb9-4937-a151-7e16634c7385")
.get("/api/v1/users/4b10e307-80d3-487d-8cf3-fd05068daa8e")
.set("Authorization", `Bearer ${token}`);
expect(response.statusCode).toBe(200);
});
});
describe("getTransaction", () => {

describe("updateUser", () => {
it("success", async () => {
const response = await request(baseUrl)
.get("/api/v1/transactions/status/2ecaed1c-bfb9-4937-a151-7e16634c7385")
.put("/api/v1/users/4b10e307-80d3-487d-8cf3-fd05068daa8e").send(
{
"name": "bimo",
"phoneNumber": "082182347623",
"familyName": "dudung",
"role": "ADMIN"
}
)
.set("Authorization", `Bearer ${token}`);
expect(response.statusCode).toBe(200);
});
});

// describe("updateTransaction", () => {
// describe("deleteUser", () => {
// it("success", async () => {
// const response = await request(baseUrl)
// .post("/api/v1/transactions/payment")
// .put("/api/v1/users/id")
// .set("Authorization", `Bearer ${token}`);
// expect(response.statusCode).toBe(200);
// });
// });
});

});
2 changes: 2 additions & 0 deletions test/unitTest/controller/user.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -168,6 +168,7 @@ describe("User API", () => {
phoneNumber: "089653421423",
familyName: "agus",
role: "BUYER",
isVerified: true,
};

it("Success", async () => {
Expand Down Expand Up @@ -221,6 +222,7 @@ describe("User API", () => {
phoneNumber: "08962394959",
familyName: "Anto",
role: "BUYER",
isVerified: true,
};

it("Success", async () => {
Expand Down
Loading