Skip to content

Commit f057ea7

Browse files
committed
Fix tests part1
1 parent 5e3978a commit f057ea7

11 files changed

Lines changed: 106 additions & 64 deletions

File tree

server/src/main/java/dev/findfirst/core/service/TypesenseService.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ public class TypesenseService {
3232
private final Client client;
3333

3434
@PostConstruct
35-
String createSchema() {
35+
public String createSchema() {
3636
var q = initRepo.findByScriptName("init");
3737
if (q == null) {
3838
var initRecord = new TypesenseInitRecord(null, "init", null, false, new Date());

server/src/main/java/dev/findfirst/users/model/user/User.java

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ public User(SignupRequest signup, String encodedPasswd) {
2828
}
2929

3030
@Id
31+
@Column("user_id")
3132
private Integer userId;
3233

3334
private boolean enabled;
@@ -38,10 +39,11 @@ public User(SignupRequest signup, String encodedPasswd) {
3839

3940
private String password;
4041

42+
@Column("user_photo")
43+
private String userPhoto;
44+
4145
@Column("role_role_id")
4246
private AggregateReference<Role, Integer> role;
4347

44-
@Column("user_photo")
45-
private String userPhoto;
4648

4749
}

server/src/main/java/dev/findfirst/users/service/UserManagementService.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -176,7 +176,7 @@ public User createNewUserAccount(SignupRequest signupRequest)
176176
// Create new user's account
177177
AggregateReference<Role, Integer> ref = AggregateReference.to(0);
178178
User user = new User(null, false, signupRequest.username(), signupRequest.username(),
179-
signupRequest.password(), ref, "");
179+
signupRequest.password(), "", ref );
180180

181181
// create a new tenant
182182
try {

server/src/main/resources/db/dev/V1.0.9__test_data_db_revamp.sql

Lines changed: 50 additions & 58 deletions
Original file line numberDiff line numberDiff line change
@@ -1,61 +1,3 @@
1-
-- login is jsmith/test
2-
insert into
3-
users(
4-
enabled,
5-
username,
6-
email,
7-
password,
8-
role_role_id,
9-
user_id
10-
)
11-
values
12-
(
13-
TRUE,
14-
'jsmith',
15-
'jsmith@google.com',
16-
'$2a$10$uhmwgpRI0vxF51s8pxt94Ojs8Cwrg7uLwhf3sK7EYv1i7QLML7aJ6', -- pwd: test
17-
0,
18-
1
19-
);
20-
21-
insert into
22-
users(
23-
enabled,
24-
username,
25-
email,
26-
password,
27-
role_role_id,
28-
user_id
29-
)
30-
values
31-
(
32-
TRUE,
33-
'king',
34-
'king@google.com',
35-
'$2a$10$uhmwgpRI0vxF51s8pxt94Ojs8Cwrg7uLwhf3sK7EYv1i7QLML7aJ6', -- pwd: test
36-
0,
37-
2
38-
);
39-
40-
insert into
41-
users(
42-
enabled,
43-
username,
44-
email,
45-
password,
46-
role_role_id,
47-
user_id
48-
)
49-
values
50-
(
51-
TRUE,
52-
'linus',
53-
'linus@google.com',
54-
'$2a$10$uhmwgpRI0vxF51s8pxt94Ojs8Cwrg7uLwhf3sK7EYv1i7QLML7aJ6', -- pwd: test
55-
0,
56-
3
57-
);
58-
591
-- jsmith's bookmarks
602
-- id: 1
613
insert into
@@ -396,4 +338,54 @@ insert into
396338
values
397339
(4, 7);
398340

341+
-- login is jsmith/test
342+
insert into
343+
users(
344+
enabled,
345+
username,
346+
email,
347+
password,
348+
role_role_id
349+
)
350+
values
351+
(
352+
TRUE,
353+
'jsmith',
354+
'jsmith@google.com',
355+
'$2a$10$uhmwgpRI0vxF51s8pxt94Ojs8Cwrg7uLwhf3sK7EYv1i7QLML7aJ6', -- pwd: test
356+
0
357+
);
399358

359+
insert into
360+
users(
361+
enabled,
362+
username,
363+
email,
364+
password,
365+
role_role_id
366+
)
367+
values
368+
(
369+
TRUE,
370+
'king',
371+
'king@google.com',
372+
'$2a$10$uhmwgpRI0vxF51s8pxt94Ojs8Cwrg7uLwhf3sK7EYv1i7QLML7aJ6', -- pwd: test
373+
0
374+
);
375+
376+
insert into
377+
users(
378+
enabled,
379+
username,
380+
email,
381+
password,
382+
role_role_id
383+
)
384+
values
385+
(
386+
TRUE,
387+
'linus',
388+
'linus@google.com',
389+
'$2a$10$uhmwgpRI0vxF51s8pxt94Ojs8Cwrg7uLwhf3sK7EYv1i7QLML7aJ6', -- pwd: test
390+
0
391+
);
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
package dev.findfirst.core.annotations;
2+
3+
import org.springframework.boot.test.mock.mockito.MockBean;
4+
import org.springframework.context.annotation.Import;
5+
6+
import dev.findfirst.core.config.TypesenseTestConfig;
7+
8+
import java.lang.annotation.ElementType;
9+
import java.lang.annotation.Retention;
10+
import java.lang.annotation.RetentionPolicy;
11+
import java.lang.annotation.Target;
12+
13+
@Target(ElementType.TYPE)
14+
@Retention(RetentionPolicy.RUNTIME)
15+
@Import(TypesenseTestConfig.class)
16+
public @interface MockTypesense {
17+
}
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
package dev.findfirst.core.config;
2+
3+
import org.springframework.boot.test.context.TestConfiguration;
4+
import org.springframework.context.annotation.Bean;
5+
6+
import dev.findfirst.core.service.TypesenseService;
7+
import static org.mockito.Mockito.when;
8+
import static org.mockito.Mockito.mock;
9+
10+
@TestConfiguration
11+
public class TypesenseTestConfig {
12+
@Bean
13+
public TypesenseService typesenseService() {
14+
TypesenseService mockService = mock(TypesenseService.class);
15+
when(mockService.createSchema()).thenReturn("Mocked Schema Creation");
16+
return mockService;
17+
}
18+
}

server/src/test/java/dev/findfirst/core/controller/BookmarkControllerTest.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
import java.util.*;
1212

1313
import dev.findfirst.core.annotations.IntegrationTest;
14+
import dev.findfirst.core.annotations.MockTypesense;
1415
import dev.findfirst.core.dto.*;
1516
import dev.findfirst.core.exceptions.BookmarkNotFoundException;
1617
import dev.findfirst.core.exceptions.TagNotFoundException;
@@ -44,6 +45,7 @@
4445

4546
@Testcontainers
4647
@IntegrationTest
48+
@MockTypesense
4749
@SpringBootTest(webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT)
4850
@Slf4j
4951
class BookmarkControllerTest {

server/src/test/java/dev/findfirst/core/controller/ImageControllerTest.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
import static dev.findfirst.utilities.HttpUtility.getHttpEntity;
44

55
import dev.findfirst.core.annotations.IntegrationTest;
6-
6+
import dev.findfirst.core.annotations.MockTypesense;
77
import lombok.RequiredArgsConstructor;
88
import org.junit.jupiter.api.Assertions;
99
import org.junit.jupiter.api.Test;
@@ -18,6 +18,7 @@
1818

1919
@Testcontainers
2020
@IntegrationTest
21+
@MockTypesense
2122
@SpringBootTest(webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT)
2223
@RequiredArgsConstructor(onConstructor = @__(@Autowired))
2324
class ImageControllerTest {

server/src/test/java/dev/findfirst/core/controller/SearchControllerTest.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
import java.util.ArrayList;
88

99
import dev.findfirst.core.annotations.IntegrationTest;
10+
import dev.findfirst.core.annotations.MockTypesense;
1011
import dev.findfirst.core.dto.BookmarkDTO;
1112
import dev.findfirst.core.dto.BookmarkOnly;
1213
import dev.findfirst.core.model.SearchBkmkByTextReq;
@@ -27,6 +28,7 @@
2728

2829
@Testcontainers
2930
@IntegrationTest
31+
@MockTypesense
3032
@SpringBootTest(webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT)
3133
@RequiredArgsConstructor(onConstructor = @__(@Autowired))
3234
class SearchControllerTest {

server/src/test/java/dev/findfirst/core/controller/TagControllerTest.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
import java.util.Optional;
1010

1111
import dev.findfirst.core.annotations.IntegrationTest;
12+
import dev.findfirst.core.annotations.MockTypesense;
1213
import dev.findfirst.core.dto.BookmarkDTO;
1314
import dev.findfirst.core.dto.TagDTO;
1415
import dev.findfirst.core.model.BookmarkTagPair;
@@ -25,6 +26,7 @@
2526
import org.testcontainers.junit.jupiter.Testcontainers;
2627

2728
@Testcontainers
29+
@MockTypesense
2830
@SpringBootTest(webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT)
2931
@IntegrationTest
3032
@Slf4j

0 commit comments

Comments
 (0)