Skip to content
Open
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
59 changes: 49 additions & 10 deletions database/changelog.yml
Original file line number Diff line number Diff line change
@@ -1,11 +1,50 @@
databaseChangeLog:
- include:
file: scripts/001-FIT-3-create_weights_table.sql
- include:
file: scripts/002-FIT-11-create_users_table.sql
- include:
file: scripts/003-FIT-23-update_weights_table_with_user_id_foreign_key.sql
- include:
file: scripts/004-FIT-30-create_products_table.sql
- include:
file: scripts/005-FIT-31-update_products_table_with_active_column.sql
- changeSet:
id: "001"
author: "auto"
context: "default"
changes:
- sqlFile:
path: "scripts/001-FIT-3-create_weights_table.sql"
- changeSet:
id: "002"
author: "auto"
context: "default"
changes:
- sqlFile:
path: "scripts/002-FIT-11-create_users_table.sql"
- changeSet:
id: "003"
author: "auto"
context: "default"
changes:
- sqlFile:
path: "scripts/003-FIT-23-update_weights_table_with_user_id_foreign_key.sql"
- changeSet:
id: "004"
author: "auto"
context: "default"
changes:
- sqlFile:
path: "scripts/004-FIT-30-create_products_table.sql"
- changeSet:
id: "005"
author: "auto"
context: "default"
changes:
- sqlFile:
path: "scripts/005-FIT-31-update_products_table_with_active_column.sql"
- changeSet:
id: "006"
author: "auto"
context: "dev"
changes:
- sqlFile:
path: "scripts/006-FIT-54-create_user_and_fill_products_table_with_initial_data.sql"
- changeSet:
id: "007"
author: "auto"
context: "test"
changes:
- sqlFile:
path: "scripts/007-create_mock_user.sql"
641 changes: 641 additions & 0 deletions database/data/001-FIT-54-insert_initial_products.sql

Large diffs are not rendered by default.

1 change: 1 addition & 0 deletions database/liquibase.properties
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
changeLogFile=changelog.yml
searchPath=/liquibase/test-resources,/liquibase
url=jdbc:postgresql://database:5432/fittracker
username=user
password=password

Large diffs are not rendered by default.

2 changes: 2 additions & 0 deletions docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -37,12 +37,14 @@ services:
container_name: 'liquibase'
volumes:
- ./database/changelog.yml:/liquibase/changelog.yml
- ./src/test/resources:/liquibase/test-resources
- ./database/scripts:/liquibase/scripts
- ./database/liquibase.properties:/liquibase.properties
depends_on:
- database
command:
- '--defaults-file=/liquibase.properties'
- '--contexts=default,dev'
- 'update'
networks:
default:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,11 @@
import jakarta.validation.constraints.Max;
import jakarta.validation.constraints.Min;
import jakarta.validation.constraints.NotBlank;
import org.hibernate.validator.constraints.Length;

public record ProductRequest(
@NotBlank(message = "Product name must not be blank")
@Length(max = 64, message = "Product name is limited to 64 characters")
String name,
@Max(value = 9999, message = "Cannot exceed 9999")
@Min(value = 0, message = "Cannot be less than 0")
Expand Down
7 changes: 5 additions & 2 deletions src/main/resources/application.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,18 +8,21 @@ spring:
url: jdbc:postgresql://${DB_HOST:localhost}:5432/fittracker
password: password
username: user
liquibase:
change-log: changelog.yml
contexts: default, dev

security:
jwt:
secret: "gHgQ0R2AbGjCwoy63dQKMCWyEhKzNwff1OHQteTTOh1EUgJJd09gLIscovYWLQf6eyr7IccpwpbvdXem"
tokenExpirationPeriodMinutes: 60
---
spring:
liquibase:
change-log: test-changelog.yml
config:
activate:
on-profile: test
liquibase:
contexts: default, test
security:
jwt:
secret: "KpQ2DTrUzvqMSkWPG4VAiBkib432jL5MtxyHcqhr5f9rmGwV1XctLGjPxdtLGPDEXkPUYVN7xxzwYsld"
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,18 @@ private static Stream<Arguments> getProductRequestTestDataProvider() {
@Nested
class Post {

@Test
void givenProductRequestWithNameLongerThan64chars_shouldReturnErrorMessage() throws Exception {
mockMvc
.perform(post(URI.create(ENDPOINT))
.contentType(APPLICATION_JSON)
.content(mapper.writeValueAsString(productRequestWithName("a".repeat(65)))))
.andExpect(status().isBadRequest())
.andExpect(content().string(errorResponseString("name", "Product name is limited to 64 characters")));

verifyNoInteractions(productService);
}

@ParameterizedTest
@MethodSource("postRequestWithBlankNames")
void givenProductRequestWithBlankName_shouldReturnErrorMessage(ProductRequest productRequest)
Expand Down
5 changes: 0 additions & 5 deletions src/test/resources/test-changelog.yml

This file was deleted.