use data and reset sql files and some clean up
This commit is contained in:
@@ -1,16 +1,10 @@
|
||||
package ltd.hlaeja.controller
|
||||
|
||||
import java.util.UUID
|
||||
import ltd.hlaeja.library.accountRegistry.Account
|
||||
import ltd.hlaeja.test.container.PostgresContainer
|
||||
import org.assertj.core.api.Assertions.assertThat
|
||||
import org.assertj.core.api.SoftAssertions
|
||||
import org.assertj.core.api.junit.jupiter.InjectSoftAssertions
|
||||
import org.assertj.core.api.junit.jupiter.SoftAssertionsExtension
|
||||
import org.junit.jupiter.api.BeforeEach
|
||||
import org.junit.jupiter.api.Nested
|
||||
import org.junit.jupiter.api.Test
|
||||
import org.junit.jupiter.api.extension.ExtendWith
|
||||
import org.junit.jupiter.params.ParameterizedTest
|
||||
import org.junit.jupiter.params.provider.CsvSource
|
||||
import org.springframework.boot.test.context.SpringBootTest
|
||||
@@ -21,7 +15,6 @@ import org.springframework.test.web.reactive.server.expectBody
|
||||
|
||||
@PostgresContainer
|
||||
@SpringBootTest(webEnvironment = RANDOM_PORT)
|
||||
@ExtendWith(SoftAssertionsExtension::class)
|
||||
class AccountsEndpoint {
|
||||
|
||||
@LocalServerPort
|
||||
@@ -52,7 +45,7 @@ class AccountsEndpoint {
|
||||
value = [
|
||||
"1,3",
|
||||
"2,0",
|
||||
]
|
||||
],
|
||||
)
|
||||
fun `get accounts with pages`(page: Int, expected: Int) {
|
||||
// when
|
||||
@@ -83,7 +76,7 @@ class AccountsEndpoint {
|
||||
"3,2,0",
|
||||
"1,5,3",
|
||||
"2,5,0",
|
||||
]
|
||||
],
|
||||
)
|
||||
fun `get accounts with pages and size to show`(page: Int, show: Int, expected: Int) {
|
||||
// when
|
||||
@@ -106,7 +99,7 @@ class AccountsEndpoint {
|
||||
"1,-1",
|
||||
"-1,1",
|
||||
"-1,-1",
|
||||
]
|
||||
],
|
||||
)
|
||||
fun `get accounts with bad pages or bad size to show`(page: Int, show: Int) {
|
||||
// when
|
||||
|
||||
@@ -6,7 +6,3 @@ spring:
|
||||
url: r2dbc:pool:postgresql://localhost:5432/test
|
||||
username: test
|
||||
password: test
|
||||
|
||||
test:
|
||||
postgres:
|
||||
init-script: postgres/schema.sql
|
||||
|
||||
5
src/integration-test/resources/postgres/data.sql
Normal file
5
src/integration-test/resources/postgres/data.sql
Normal file
@@ -0,0 +1,5 @@
|
||||
-- Test data
|
||||
insert into public.accounts (id, created_at, updated_at, enabled, username, password, roles)
|
||||
values ('00000000-0000-7000-0000-000000000001'::uuid, '2000-01-01 00:00:00.000001 +00:00', '2000-01-01 00:00:01.000001 +00:00', true, 'admin', '$2a$12$KoXBoLOANMK11J4xeJHPA.Sy0FG.m8KWk7P4XFsMO.ZbFmFI2DckK', 'ROLE_ADMIN'),
|
||||
('00000000-0000-7000-0000-000000000002'::uuid, '2000-01-01 00:00:00.000001 +00:00', '2000-01-01 00:00:01.000001 +00:00', true, 'user', '$2a$12$KoXBoLOANMK11J4xeJHPA.Sy0FG.m8KWk7P4XFsMO.ZbFmFI2DckK', 'ROLE_USER'),
|
||||
('00000000-0000-7000-0000-000000000003'::uuid, '2000-01-01 00:00:00.000001 +00:00', '2000-01-01 00:00:01.000001 +00:00', false, 'disabled', '$2a$12$KoXBoLOANMK11J4xeJHPA.Sy0FG.m8KWk7P4XFsMO.ZbFmFI2DckK', 'ROLE_USER');
|
||||
11
src/integration-test/resources/postgres/reset.sql
Normal file
11
src/integration-test/resources/postgres/reset.sql
Normal file
@@ -0,0 +1,11 @@
|
||||
-- Disable triggers on the tables
|
||||
ALTER TABLE accounts DISABLE TRIGGER ALL;
|
||||
ALTER TABLE accounts_audit DISABLE TRIGGER ALL;
|
||||
|
||||
-- Truncate tables
|
||||
TRUNCATE TABLE accounts_audit;
|
||||
TRUNCATE TABLE accounts;
|
||||
|
||||
-- Enable triggers on the account table
|
||||
ALTER TABLE accounts ENABLE TRIGGER ALL;
|
||||
ALTER TABLE accounts_audit ENABLE TRIGGER ALL;
|
||||
@@ -72,7 +72,6 @@ CREATE OR REPLACE TRIGGER accounts_audit_trigger
|
||||
ON public.accounts
|
||||
FOR EACH ROW
|
||||
EXECUTE FUNCTION public.accounts_audit();
|
||||
|
||||
-- Test data
|
||||
insert into public.accounts (id, created_at, updated_at, enabled, username, password, roles)
|
||||
values ('00000000-0000-7000-0000-000000000001'::uuid, '2000-01-01 00:00:00.000001 +00:00', '2000-01-01 00:00:01.000001 +00:00', true, 'admin', '$2a$12$KoXBoLOANMK11J4xeJHPA.Sy0FG.m8KWk7P4XFsMO.ZbFmFI2DckK', 'ROLE_ADMIN'),
|
||||
|
||||
@@ -1,12 +1,10 @@
|
||||
package ltd.hlaeja.service
|
||||
|
||||
import io.github.oshai.kotlinlogging.KotlinLogging
|
||||
import java.lang.IllegalArgumentException
|
||||
import java.util.UUID
|
||||
import ltd.hlaeja.entity.AccountEntity
|
||||
import ltd.hlaeja.repository.AccountRepository
|
||||
import org.springframework.dao.DuplicateKeyException
|
||||
import org.springframework.http.HttpStatus
|
||||
import org.springframework.http.HttpStatus.BAD_REQUEST
|
||||
import org.springframework.http.HttpStatus.CONFLICT
|
||||
import org.springframework.http.HttpStatus.NOT_FOUND
|
||||
|
||||
@@ -13,7 +13,7 @@ class AccountValidator : ConstraintValidator<ValidAccount, Any> {
|
||||
}
|
||||
}
|
||||
|
||||
private fun Account.Request.validate(): Boolean = username.isNotBlank()
|
||||
&& password?.isNotBlank() ?: true
|
||||
&& roles.isNotEmpty()
|
||||
private fun Account.Request.validate(): Boolean = username.isNotBlank() &&
|
||||
password?.isNotBlank() ?: true &&
|
||||
roles.isNotEmpty()
|
||||
}
|
||||
|
||||
@@ -11,5 +11,5 @@ import kotlin.reflect.KClass
|
||||
annotation class ValidAccount(
|
||||
val message: String = "Roles must not be empty",
|
||||
val groups: Array<KClass<out Any>> = [],
|
||||
val payload: Array<KClass<out Payload>> = []
|
||||
val payload: Array<KClass<out Payload>> = [],
|
||||
)
|
||||
|
||||
@@ -1,6 +1,5 @@
|
||||
package ltd.hlaeja.validator
|
||||
|
||||
|
||||
import io.mockk.mockk
|
||||
import ltd.hlaeja.library.accountRegistry.Account
|
||||
import org.assertj.core.api.Assertions.assertThat
|
||||
@@ -17,7 +16,7 @@ class AccountValidatorTest {
|
||||
username = "validUser",
|
||||
password = "strongPassword",
|
||||
enabled = true,
|
||||
roles = listOf("USER", "TEST")
|
||||
roles = listOf("USER", "TEST"),
|
||||
)
|
||||
|
||||
// when
|
||||
@@ -34,7 +33,7 @@ class AccountValidatorTest {
|
||||
username = "validUser",
|
||||
password = null,
|
||||
enabled = true,
|
||||
roles = listOf("USER")
|
||||
roles = listOf("USER"),
|
||||
)
|
||||
|
||||
// when
|
||||
@@ -51,7 +50,7 @@ class AccountValidatorTest {
|
||||
username = "",
|
||||
password = "strongPassword",
|
||||
enabled = true,
|
||||
roles = listOf("USER")
|
||||
roles = listOf("USER"),
|
||||
)
|
||||
|
||||
// when
|
||||
@@ -68,7 +67,7 @@ class AccountValidatorTest {
|
||||
username = "validUser",
|
||||
password = "",
|
||||
enabled = true,
|
||||
roles = listOf("USER")
|
||||
roles = listOf("USER"),
|
||||
)
|
||||
|
||||
// when
|
||||
@@ -85,7 +84,7 @@ class AccountValidatorTest {
|
||||
username = "validUser",
|
||||
password = "",
|
||||
enabled = true,
|
||||
roles = emptyList()
|
||||
roles = emptyList(),
|
||||
)
|
||||
|
||||
// when
|
||||
|
||||
Reference in New Issue
Block a user