Skip to content

Commit

Permalink
fix: use postgres syntax in test
Browse files Browse the repository at this point in the history
  • Loading branch information
tkuzynow committed Mar 1, 2024
1 parent fbac819 commit a035440
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ public ScheduleRepository(@Qualifier("dbTemplate") NamedParameterJdbcTemplate db

public Set<Integer> deleteUserSchedules(Long calcomUserId) {
var originalScheduleIds = getScheduleIdsByUserId(db, calcomUserId);
String DELETE_SCHEDULE = "DELETE FROM SCHEDULE where userId = :userId";
String DELETE_SCHEDULE = "DELETE FROM \"Schedule\" where \"userId\" = :userId";
SqlParameterSource parameters = new MapSqlParameterSource("userId", calcomUserId);
db.update(DELETE_SCHEDULE, parameters);
var leftScheduleIds = getScheduleIdsByUserId(db, calcomUserId);
Expand All @@ -67,7 +67,7 @@ public Set<Integer> getScheduleIdsByUserId(NamedParameterJdbcTemplate jdbcTempla
Set<Integer> scheduleIds = Sets.newHashSet();
Map<String, Object> params = new HashMap<>();
params.put("userId", userId);
String sql = "SELECT id FROM SCHEDULE";
String sql = "SELECT \"id\" FROM \"Schedule\" WHERE \"userId\" = :userId";
try {
List<Map<String, Object>> rows = jdbcTemplate.queryForList(sql, params);
for (Map<String, Object> row : rows) {
Expand Down
2 changes: 1 addition & 1 deletion src/main/resources/application-testing.properties
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ keycloak.config.app-client-id=app-ci
spring.datasource.driver-class-name=org.h2.Driver
spring.datasource.url=jdbc:h2:mem:db;DB_CLOSE_DELAY=-1
spring.sql.init.schema-locations=classpath*:database/AppointmentServiceDatabase.sql
calcom.database.url=jdbc:h2:mem:db;DB_CLOSE_DELAY=-1
calcom.database.url=jdbc:h2:mem:db;DB_CLOSE_DELAY=-1;MODE=PostgreSQL
calcom.database.username=appointmentservice
calcom.database.password=appointmentservice
calcom.database.driverClass=org.h2.Driver
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,15 +28,15 @@ class ScheduleRepositoryTest {

@Before
public void setUp() {
jdbcTemplate.execute("DROP TABLE IF EXISTS SCHEDULE");
jdbcTemplate.execute("DROP TABLE IF EXISTS \"Schedule\"");
}
@Test
void deleteUserSchedules_Should_DeleteSchedulesPerUserId() {
// given
inititalizeDB();

jdbcTemplate.execute("INSERT INTO SCHEDULE (id, userId, name) VALUES (1, 1, 'DEFAULT_SCHEDULE')");
jdbcTemplate.execute("INSERT INTO SCHEDULE (id, userId, name) VALUES (2, 1, 'DEFAULT_SCHEDULE')");
jdbcTemplate.execute("INSERT INTO \"Schedule\" (\"id\", \"userId\", \"name\") VALUES (1, 1, 'DEFAULT_SCHEDULE')");
jdbcTemplate.execute("INSERT INTO \"Schedule\" (\"id\", \"userId\", \"name\") VALUES (2, 1, 'DEFAULT_SCHEDULE')");
// when
Set<Integer> integers = scheduleRepository.deleteUserSchedules(1L);
// then
Expand All @@ -47,12 +47,12 @@ void deleteUserSchedules_Should_DeleteSchedulesPerUserId() {
private void inititalizeDB() {
// we can't use @Sql annotation here because it's not visible in jdbcTemplate,
// probably because there are defined multiple jdbc templates in this project for different datasources
jdbcTemplate.execute("create table SCHEDULE\n"
jdbcTemplate.execute("create table \"Schedule\"\n"
+ "(\n"
+ " id integer not null\n"
+ " \"id\" integer not null\n"
+ " primary key,\n"
+ " userId integer not null,\n"
+ " name varchar(255) not null\n"
+ " \"userId\" integer not null,\n"
+ " \"name\" varchar(255) not null\n"
+ ");");
}

Expand Down

0 comments on commit a035440

Please sign in to comment.