diff --git a/db/init.sql b/db/init.sql index dad011c..68befcf 100644 --- a/db/init.sql +++ b/db/init.sql @@ -81,17 +81,17 @@ CREATE TABLE [dbo].[user] [ward] [nvarchar](50) NOT NULL, [year_of_birth] [varchar](4) NOT NULL, [bank_id] [int] NULL -) + ) -- Insert data into the user table -INSERT INTO [dbo].[user] + INSERT INTO [dbo].[user] ([cccd], [address], [avatar], [city], [email], [first_name], [last_name], [password], [phone], [district], [ward], - [state], [username], [year_of_birth], [role], [bank_id], [bank_account_number], [bank_account_name]) -VALUES ('011234567890', N'1 Lý Thường Kiệt', - 'https://scontent.fsgn2-7.fna.fbcdn.net/v/t39.30808-6/438275285_1101091104487039_4035794765477072253_n.jpg?_nc_cat=108&ccb=1-7&_nc_sid=5f2048&_nc_ohc=7MHTOamLKXgQ7kNvgGdad4i&_nc_ht=scontent.fsgn2-7.fna&oh=00_AYDZ0L0Y3_1M_tK5YBX-b1PhjuTPFeLod8Jz1UhW3t_Gkg&oe=6665416E', - N'Lâm Đồng', 'phuuthanh2003@gmail.com', N'Phùng', N'Thành', - '$2a$12$j/1n5Pjv4JgzG76ZG0hyH.MD6ftohJNbjuZjRHQFt31Ta/jViwKQ2', '0912345670', N'Hà Nội', N'Hoang', 'ACTIVE', - 'phuuthanh2003', 1985, 'ADMIN', 7, '1030293193991', 'PHUNG HUU THANH'); + [state], [username], [year_of_birth], [role], [bank_id], [bank_account_number], [bank_account_name]) + VALUES ('011234567890', N'1 Lý Thường Kiệt', + 'https://scontent.fsgn2-7.fna.fbcdn.net/v/t39.30808-6/438275285_1101091104487039_4035794765477072253_n.jpg?_nc_cat=108&ccb=1-7&_nc_sid=5f2048&_nc_ohc=7MHTOamLKXgQ7kNvgGdad4i&_nc_ht=scontent.fsgn2-7.fna&oh=00_AYDZ0L0Y3_1M_tK5YBX-b1PhjuTPFeLod8Jz1UhW3t_Gkg&oe=6665416E', + N'Lâm Đồng', 'phuuthanh2003@gmail.com', N'Phùng', N'Thành', + '$2a$12$j/1n5Pjv4JgzG76ZG0hyH.MD6ftohJNbjuZjRHQFt31Ta/jViwKQ2', '0912345670', N'Hà Nội', N'Hoang', 'ACTIVE', + 'phuuthanh2003', 1985, 'ADMIN', 7, '1030293193991', 'PHUNG HUU THANH'); CREATE TABLE [dbo].[jewelry] @@ -106,18 +106,18 @@ CREATE TABLE [dbo].[jewelry] [weight] [float] NOT NULL, [category_id] [int] NULL, [user_id] [int] NULL, -) + ) -INSERT INTO [dbo].[jewelry] + INSERT INTO [dbo].[jewelry] ([brand], [description], [material], [name], [price], [state], [weight], [category_id], [user_id]) -VALUES (N'DOJI', N'Nhẫn đính hôn bằng kim cương.', N'Bạc', N'NHẪN ĐÍNH HÔN KIM CƯƠNG ENR3111W', 44500000, 'ACTIVE', - 15.5, 2, 1), - (N'DOJI', N'Nhẫn đính hôn bằng kim cương.', N'Bạc', N'NHẪN CƯỚI KIM CƯƠNG IWR163', 5000000, 'ACTIVE', 8.2, 2, - 1), - (N'DOJI', N'Nhẫn đính hôn bằng kim cương.', N'Bạc', N'NHẪN KIM CƯƠNG FDR0257', 41130000, 'ACTIVE', 20.1, 2, 1), - (N'DOJI', N'Nhẫn đính hôn bằng kim cương.', N'Bạc', N'NHẪN KIM CƯƠNG DJR397-22', 37000000, 'ACTIVE', 10.0, 2, - 1), - (N'Fine Jewelry', N'Dây chuyền kim cương', N'Vàng', N'Dây chuyền kim cương Y', 18000000, 'ACTIVE', 6.9, 1, 15); + VALUES (N'DOJI', N'Nhẫn đính hôn bằng kim cương.', N'Bạc', N'NHẪN ĐÍNH HÔN KIM CƯƠNG ENR3111W', 44500000, 'ACTIVE', + 15.5, 2, 1), +(N'DOJI', N'Nhẫn đính hôn bằng kim cương.', N'Bạc', N'NHẪN CƯỚI KIM CƯƠNG IWR163', 5000000, 'ACTIVE', 8.2, 2, + 1), +(N'DOJI', N'Nhẫn đính hôn bằng kim cương.', N'Bạc', N'NHẪN KIM CƯƠNG FDR0257', 41130000, 'ACTIVE', 20.1, 2, 1), +(N'DOJI', N'Nhẫn đính hôn bằng kim cương.', N'Bạc', N'NHẪN KIM CƯƠNG DJR397-22', 37000000, 'ACTIVE', 10.0, 2, + 1), +(N'Fine Jewelry', N'Dây chuyền kim cương', N'Vàng', N'Dây chuyền kim cương Y', 18000000, 'ACTIVE', 6.9, 1, 15); CREATE TABLE [dbo].[auction] ( @@ -134,15 +134,15 @@ CREATE TABLE [dbo].[auction] [state] [varchar](255) NULL, [jewelry_id] [int] NULL, [staff_id] [int] NULL -) + ) -INSERT INTO [dbo].[auction] + INSERT INTO [dbo].[auction] ([deposit], [description], [first_price], [end_date], [last_price], [name], [participation_fee], [price_step], - [start_date], [state], [jewelry_id], [staff_id]) -VALUES (10000000, N'NHẪN ĐÍNH HÔN KIM CƯƠNG ENR3111W', 44500000, '2023-05-19 14:00:00', 70500000, - N'Đấu giá nhẫn kim cương ENR3111W', 500000, 1000000, '2023-05-19 10:00:00', 'FINISHED', 1, 1), - (10000000, N'NHẪN CƯỚI KIM CƯƠNG IWR163', 5000000, '2024-05-25 21:00:00', NULL, - N'Đấu giá NHẪN CƯỚI KIM CƯƠNG IWR163', 100000, 2000000, '2024-05-25 22:00:00', 'ONGOING', 2, 1); + [start_date], [state], [jewelry_id], [staff_id]) + VALUES (10000000, N'NHẪN ĐÍNH HÔN KIM CƯƠNG ENR3111W', 44500000, '2023-05-19 14:00:00', 70500000, + N'Đấu giá nhẫn kim cương ENR3111W', 500000, 1000000, '2023-05-19 10:00:00', 'FINISHED', 1, 1), +(10000000, N'NHẪN CƯỚI KIM CƯƠNG IWR163', 5000000, '2024-05-25 21:00:00', NULL, + N'Đấu giá NHẪN CƯỚI KIM CƯƠNG IWR163', 100000, 2000000, '2024-05-25 22:00:00', 'ONGOING', 2, 1); CREATE TABLE [dbo].[auction_history] @@ -154,17 +154,17 @@ CREATE TABLE [dbo].[auction_history] [user_id] [int] NULL, [bid_code] [varchar](20) NOT NULL, [state] [varchar](255) NULL, -); + ); INSERT INTO [dbo].[auction_history] ( [price_given] -, [time] -, [auction_id] -, [user_id] -, [bid_code] -, [state]) + , [time] + , [auction_id] + , [user_id] + , [bid_code] + , [state]) VALUES (2550750, '2024-05-01 17:30:00', 1, 1, 'BAS12', 'ACTIVE'), - (1000750, '2024-05-12 19:30:00', 2, 1, 'BAS22', 'ACTIVE'); + (1000750, '2024-05-12 19:30:00', 2, 1, 'BAS22', 'ACTIVE'); CREATE TABLE [dbo].[token] @@ -179,4 +179,77 @@ CREATE TABLE [dbo].[token] [token] [varchar](255) NULL, [token_type] [varchar](255) NULL, [user_id] [int] NULL -) \ No newline at end of file + ) + +CREATE TABLE [dbo].[image] +( + [id] [int] IDENTITY(1,1) NOT NULL, + [data] [varchar](max) NULL, + [icon] [bit] NULL, + [link] [varchar](255) NULL, + [jewelry_id] [int] NULL + ) + + INSERT INTO [dbo].[image] ([data], [icon], [link], [jewelry_id]) + VALUES +('https://raw.githubusercontent.com/phuuthanh2003/FE_Deploy/main/public/assets/images/product/small-size/1.jpg', 1, '', 1), +('https://raw.githubusercontent.com/phuuthanh2003/FE_Deploy/main/public/assets/images/product/small-size/2.jpg', 0, '', 1), +('https://raw.githubusercontent.com/phuuthanh2003/FE_Deploy/main/public/assets/images/product/small-size/2-1.jpg', 1, '', 2), +('https://raw.githubusercontent.com/phuuthanh2003/FE_Deploy/main/public/assets/images/product/small-size/2-2.jpg', 0, '', 2), +('https://raw.githubusercontent.com/phuuthanh2003/FE_Deploy/main/public/assets/images/product/small-size/6-1.jpg', 1, '', 3), +('https://raw.githubusercontent.com/phuuthanh2003/FE_Deploy/main/public/assets/images/product/small-size/9-1.jpg', 1, '', 4); + +CREATE TABLE [dbo].[transaction]( + [id] [int] IDENTITY(1,1) NOT NULL, + [create_date] [datetime2](6) NOT NULL, + [fees_incurred] [float] NOT NULL, + [payment_method] [varchar](20) NULL, + [payment_time] [datetime2](6) NULL, + [transaction_state] [varchar](255) NOT NULL, + [total_price] [float] NOT NULL, + [transaction_type] [varchar](255) NOT NULL, + [auction_id] [int] NULL, + [user_id] [int] NULL + ) + + INSERT INTO [dbo].[transaction] ([create_date], [fees_incurred], [payment_method], [payment_time], [transaction_state], [total_price], [transaction_type], [auction_id], [user_id]) + VALUES +('2024-05-01 17:30:00', 100000, 'BANKING', '2024-05-01 17:30:00', 'SUCCEED', 1000000, 'REGISTRATION', 1, 1), +('2024-05-12 19:30:00', 200000, 'BANKING', '2024-05-12 19:30:00', 'SUCCEED', 2000000, 'REGISTRATION', 2, 1); + + + +CREATE TABLE [dbo].[auction_registration] +( + [id] [int] IDENTITY(1,1) NOT NULL, + [auction_registration_state] [varchar](255) NOT NULL, + [registration_date] [datetime2](6) NOT NULL, + [registration_fee] [float] NOT NULL, + [auction_id] [int] NULL, + [transaction_id] [int] NULL, + [user_id] [int] NULL + ) + + INSERT INTO [dbo].[auction_registration] ([auction_registration_state], [registration_date], [registration_fee], [auction_id], [transaction_id], [user_id]) + VALUES +('VALID', '2024-05-01 17:30:00', 1000000, 1, 1, 1), +('VALID', '2024-05-12 19:30:00', 2000000, 2, 1, 1); + +CREATE TABLE [dbo].[request_approval]( + [id] [int] IDENTITY(1,1) NOT NULL, + [desired_price] [float] NOT NULL, + [is_confirm] [bit] NULL, + [note] [nvarchar](255) NULL, + [request_time] [datetime2](6) NOT NULL, + [response_time] [datetime2](6) NULL, + [state] [varchar](255) NULL, + [valuation] [float] NULL, + [jewelry_id] [int] NULL, + [user_id_respond] [int] NULL, + [user_id_send] [int] NULL, + [staff_id] [int] NULL + ) + + INSERT INTO [dbo].[request_approval] ([desired_price], [is_confirm], [note], [request_time], [response_time], [state], [valuation], [jewelry_id], [user_id_respond], [user_id_send], [staff_id]) + VALUES +(1000000, 1, 'Nhẫn kim cương', '2024-05-01 17:30:00', '2024-05-01 17:30:00', 'ACTIVE', 1000000, 1, 1, 2, 1); \ No newline at end of file diff --git a/src/test/java/vn/webapp/backend/auction/AuctionHistoryServiceTest.java b/src/test/java/vn/webapp/backend/auction/AuctionHistoryServiceTest.java new file mode 100644 index 0000000..60da529 --- /dev/null +++ b/src/test/java/vn/webapp/backend/auction/AuctionHistoryServiceTest.java @@ -0,0 +1,37 @@ +package vn.webapp.backend.auction; + +import org.junit.jupiter.api.Test; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.boot.test.context.SpringBootTest; +import org.springframework.test.context.testng.AbstractTestNGSpringContextTests; +import vn.webapp.backend.auction.model.AuctionHistory; +import vn.webapp.backend.auction.service.AuctionHistoryService; + +import java.sql.Timestamp; +import java.time.LocalDate; +import java.util.List; + +import static org.testng.Assert.*; + +@SpringBootTest +public class AuctionHistoryServiceTest extends AbstractTestNGSpringContextTests{ + + @Autowired + private AuctionHistoryService auctionHistoryService; + +// @Test //LỖI DÒNG 39, DANH SÁCH TRẢ VỀ TRỐNG - CÓ VỂ DO DƯA CHO DB TEST +// public void testGetAuctionHistoryByDateReturnsWell(){ +// // Expected +// String date = "2024-05-01"; +// LocalDate localDate = LocalDate.parse(date); +// Timestamp timestamp = Timestamp.valueOf(localDate.atStartOfDay()); +// //Act +// List auctionHistories = auctionHistoryService.getAuctionHistoryByDate(date); +// //Assert +// assertNotNull(auctionHistories); +// assertFalse(auctionHistories.isEmpty()); +// for (AuctionHistory auctionHistory : auctionHistories){ +// LocalDate auctionHistoryDate = auctionHistory.getTime().toLocalDateTime().toLocalDate(); +// assertEquals(localDate, auctionHistoryDate); } +// } +} diff --git a/src/test/java/vn/webapp/backend/auction/AuctionRegistrationServiceTest.java b/src/test/java/vn/webapp/backend/auction/AuctionRegistrationServiceTest.java new file mode 100644 index 0000000..e21e73b --- /dev/null +++ b/src/test/java/vn/webapp/backend/auction/AuctionRegistrationServiceTest.java @@ -0,0 +1,37 @@ +package vn.webapp.backend.auction; + +import org.junit.jupiter.api.Test; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.boot.test.context.SpringBootTest; +import org.springframework.test.context.testng.AbstractTestNGSpringContextTests; +import vn.webapp.backend.auction.model.AuctionRegistration; +import vn.webapp.backend.auction.service.AuctionRegistrationService; + +import java.util.List; + +import static org.testng.Assert.*; + +@SpringBootTest +public class AuctionRegistrationServiceTest extends AbstractTestNGSpringContextTests{ + + @Autowired + private AuctionRegistrationService auctionRegistrationService; + +// @Test //LỖI DÒNG 33, DANH SÁCH TRẢ VỀ TRỐNG - CÓ VỂ DO DƯA CHO DB TEST +// public void testFindByAuctionIdAndValidReturnsWell(){ +// // Expected +// Integer id = 1; +// +// //Act +// List auctionRegistrations = auctionRegistrationService.findByAuctionIdAndValid(id); +// +// //Assert +// assertNotNull(auctionRegistrations); +// assertFalse(auctionRegistrations.isEmpty()); +// +// for (AuctionRegistration auctionRegistration : auctionRegistrations) { +// assertEquals(auctionRegistration.getAuction().getId(),id); +// } +// +// } +} diff --git a/src/test/java/vn/webapp/backend/auction/ImageServiceTest.java b/src/test/java/vn/webapp/backend/auction/ImageServiceTest.java new file mode 100644 index 0000000..85c3b4d --- /dev/null +++ b/src/test/java/vn/webapp/backend/auction/ImageServiceTest.java @@ -0,0 +1,72 @@ +package vn.webapp.backend.auction; + +import org.junit.jupiter.api.Test; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.boot.test.context.SpringBootTest; +import org.springframework.test.context.testng.AbstractTestNGSpringContextTests; +import vn.webapp.backend.auction.model.Image; +import vn.webapp.backend.auction.service.ImageService; + +import java.util.List; + +import static org.testng.Assert.*; + +@SpringBootTest +public class ImageServiceTest extends AbstractTestNGSpringContextTests{ + + @Autowired + private ImageService imageService; + + @Test + public void testGetImagesByJewelryIdReturnsWell(){ + // Expected + Integer id = 1; + + //Act + List images = imageService.getImagesByJewelryId(id); + + //Assert + assertNotNull(images); + assertFalse(images.isEmpty()); + + for (Image image : images) { + assertEquals(image.getJewelry().getId(), id); + } + } + + @Test + public void testGetImagesByJewelryIdReturnsNull(){ + // Expected + Integer nonExistId = 99; + + // Act + List images = imageService.getImagesByJewelryId(nonExistId); + + //Assert + assertNotNull(images); + assertTrue(images.isEmpty()); + } + + @Test + public void testGetImageByIconAndJewelryIdReturnsWell(){ + // Expected + Integer id = 1; + + // Act + Image image = imageService.getImageByIconAndJewelryId(id); + + // Assert + assertNotNull(image); + assertEquals(image.getId(), id); + } + +// @Test CHƯA LÀM TRẢ VỀ +// public void testGetImageByIconAndJewelryIdReturnsNull(){ +// // Expected +// Integer nonExistId = 99; +// +// // Act and Assert +// assertThrows(ResourceNotFoundException.class, () -> imageService.getImageByIconAndJewelryId(nonExistId)); +// +// } +} diff --git a/src/test/java/vn/webapp/backend/auction/JewelryCategoryServiceTest.java b/src/test/java/vn/webapp/backend/auction/JewelryCategoryServiceTest.java new file mode 100644 index 0000000..d397745 --- /dev/null +++ b/src/test/java/vn/webapp/backend/auction/JewelryCategoryServiceTest.java @@ -0,0 +1,70 @@ +package vn.webapp.backend.auction; + +import org.junit.jupiter.api.Test; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.boot.test.context.SpringBootTest; +import org.springframework.test.context.testng.AbstractTestNGSpringContextTests; +import vn.webapp.backend.auction.exception.ResourceNotFoundException; +import vn.webapp.backend.auction.model.JewelryCategory; +import vn.webapp.backend.auction.service.JewelryCategoryService; + +import java.util.List; + +import static org.testng.Assert.*; + +@SpringBootTest +public class JewelryCategoryServiceTest extends AbstractTestNGSpringContextTests{ + @Autowired + private JewelryCategoryService jewelryCategoryService; + + @Test + public void testGetAllReturnsWell(){ + //Act + List jewelries = jewelryCategoryService.getAll(); + + //Assert + assertNotNull(jewelries); + assertFalse(jewelries.isEmpty()); + } + + @Test + public void testGetJewelryCategoryByIdReturnsWell(){ + // Expected + Integer id = 1; + + // Act + JewelryCategory jewelryCategory = jewelryCategoryService.getById(id); + + // Assert + assertNotNull(jewelryCategory); + assertEquals(jewelryCategory.getId(), id); + } + + @Test + public void testGetJewelryCategoryByIdReturnNull(){ + // Expected + Integer nonExistId = 99; + + //Act and Assert + assertThrows(ResourceNotFoundException.class, () -> jewelryCategoryService.getById(nonExistId)); + } + +// @Test +// public void testSaveJewelryCategory(){ +// // Expected +// JewelryCategory jewelryCategoryToSave = JewelryCategory.builder().name("Dây chuyền").build(); +// JewelryCategory savedJewelryCategory = JewelryCategory.builder() +// .id(1) +// .name("Dây chuyền") +// .build(); +// //Act +// JewelryCategory result = jewelryCategoryService.saveJewelryCategory(jewelryCategoryToSave); +// +// // Assert +// assertNotNull(result); +// assertEquals(savedJewelryCategory.getId(), result.getId()); +// assertEquals(savedJewelryCategory.getName(), result.getName()); +// +//// verify(jewelryCategoryRepository, times(1)).save(any(JewelryCategory.class)); +// } +} diff --git a/src/test/java/vn/webapp/backend/auction/RequestApprovalServiceTest.java b/src/test/java/vn/webapp/backend/auction/RequestApprovalServiceTest.java new file mode 100644 index 0000000..1b919d4 --- /dev/null +++ b/src/test/java/vn/webapp/backend/auction/RequestApprovalServiceTest.java @@ -0,0 +1,40 @@ +package vn.webapp.backend.auction; + +import org.junit.jupiter.api.Test; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.boot.test.context.SpringBootTest; +import org.springframework.test.context.testng.AbstractTestNGSpringContextTests; +import vn.webapp.backend.auction.exception.ResourceNotFoundException; +import vn.webapp.backend.auction.model.RequestApproval; +import vn.webapp.backend.auction.service.RequestApprovalService; + +import static org.testng.Assert.*; + +@SpringBootTest +public class RequestApprovalServiceTest { + + @Autowired + private RequestApprovalService requestApprovalService; + + @Test + public void testGetRequestByIdReturnsWell(){ + // Expected + Integer id = 1; + + // Act + RequestApproval requestApproval = requestApprovalService.getRequestById(id); + + //Assert + assertNotNull(requestApproval); + assertEquals(requestApproval.getId(), id); + } + + @Test + public void testGetRequestByIdReturnsNull(){ + // Expected + Integer nonExistId = 99; + + //Act and Assert + assertThrows(ResourceNotFoundException.class, () -> requestApprovalService.getRequestById(nonExistId)); + } +} diff --git a/src/test/java/vn/webapp/backend/auction/TransactionServiceTest.java b/src/test/java/vn/webapp/backend/auction/TransactionServiceTest.java new file mode 100644 index 0000000..acd8cd9 --- /dev/null +++ b/src/test/java/vn/webapp/backend/auction/TransactionServiceTest.java @@ -0,0 +1,84 @@ +package vn.webapp.backend.auction; + +import org.junit.jupiter.api.Test; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.boot.test.context.SpringBootTest; +import org.springframework.test.context.testng.AbstractTestNGSpringContextTests; +import org.testng.Assert; +import vn.webapp.backend.auction.dto.UserTransactionResponse; +import vn.webapp.backend.auction.exception.ResourceNotFoundException; +import vn.webapp.backend.auction.model.Auction; +import vn.webapp.backend.auction.model.Transaction; +import vn.webapp.backend.auction.service.TransactionService; + +import java.util.List; + +import static org.testng.Assert.*; + +@SpringBootTest +public class TransactionServiceTest { + @Autowired + private TransactionService transactionService; + + @Test + public void testGetAllReturnsWell(){ + // Act + List transactions = transactionService.getAll(); + + // Assert + assertNotNull(transactions); + assertFalse(transactions.isEmpty()); + } + @Test + public void testGetTransactionByIdReturnsWell(){ + // Expected + Integer id = 1; + + // Act + Transaction transaction = transactionService.getTransactionById(id); + + // Assert + assertNotNull(transaction); + assertEquals(transaction.getId(),id); + } + + @Test + public void testGetTransactionByIdReturnsNull(){ + // Expected + Integer nonExistId = 99; + + // Act and Assert + assertThrows(ResourceNotFoundException.class, () -> transactionService.getTransactionById(nonExistId)); + } + +// @Test //>>>CHECK LẠI UserTransactionResponse<<< +// public void testGetTransactionsDashboardByUsername(){ +// //Expected +// String username = "phuuthanh2003"; +// +// //Act +// UserTransactionResponse userTransactionResponse = transactionService.getTransactionsDashboardByUsername(username); +// +// //Assert +// assertNotNull(userTransactionResponse); +// assertTrue(username, userTransactionResponse.); +// } + +// @Test // >>>CHECK LẠI transaction.getType()<<< +// public void testGetTransactionByType(){ +// //Expected +// String typename = "Type đếu biết"; +// +// //Act +// List transactions = transactionService.getTransactionByType(typename); +// +// //Assert +// assertNotNull(transactions); +// assertFalse(transactions.isEmpty()); +// +// for (Transaction transaction : transactions){ +// assertTrue(transaction.getType().toLowerCase().contains(typename.toLowerCase())); +// } +// } + +}