Skip to content

Commit

Permalink
Merge pull request #66 from phuuthanh2003/develop
Browse files Browse the repository at this point in the history
Develop
  • Loading branch information
phuuthanh-dev authored Jun 13, 2024
2 parents 2ec93f4 + 94a0786 commit 6dc687c
Show file tree
Hide file tree
Showing 7 changed files with 446 additions and 33 deletions.
139 changes: 106 additions & 33 deletions db/init.sql
Original file line number Diff line number Diff line change
Expand Up @@ -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', '[email protected]', 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', '[email protected]', 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]
Expand All @@ -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]
(
Expand All @@ -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]
Expand All @@ -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]
Expand All @@ -179,4 +179,77 @@ CREATE TABLE [dbo].[token]
[token] [varchar](255) NULL,
[token_type] [varchar](255) NULL,
[user_id] [int] NULL
)
)

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);
Original file line number Diff line number Diff line change
@@ -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<AuctionHistory> auctionHistories = auctionHistoryService.getAuctionHistoryByDate(date);
// //Assert
// assertNotNull(auctionHistories);
// assertFalse(auctionHistories.isEmpty());
// for (AuctionHistory auctionHistory : auctionHistories){
// LocalDate auctionHistoryDate = auctionHistory.getTime().toLocalDateTime().toLocalDate();
// assertEquals(localDate, auctionHistoryDate); }
// }
}
Original file line number Diff line number Diff line change
@@ -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<AuctionRegistration> auctionRegistrations = auctionRegistrationService.findByAuctionIdAndValid(id);
//
// //Assert
// assertNotNull(auctionRegistrations);
// assertFalse(auctionRegistrations.isEmpty());
//
// for (AuctionRegistration auctionRegistration : auctionRegistrations) {
// assertEquals(auctionRegistration.getAuction().getId(),id);
// }
//
// }
}
72 changes: 72 additions & 0 deletions src/test/java/vn/webapp/backend/auction/ImageServiceTest.java
Original file line number Diff line number Diff line change
@@ -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<Image> 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<Image> 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));
//
// }
}
Loading

0 comments on commit 6dc687c

Please sign in to comment.