Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore/add test coverage restrictions #74

Merged
merged 8 commits into from
Aug 16, 2024
Merged
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
79 changes: 78 additions & 1 deletion backend/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,84 @@
</excludes>
</configuration>
</plugin>
<plugin>
<groupId>org.jacoco</groupId>
<artifactId>jacoco-maven-plugin</artifactId>
<version>0.8.12</version>
<executions>
<execution>
<goals>
<goal>prepare-agent</goal>
</goals>
</execution>
<execution>
<id>check</id>
<goals>
<goal>check</goal>
</goals>
<configuration>
<rules>
<rule>
<element>CLASS</element>
<limits>
<limit>
<counter>LINE</counter>
<value>COVEREDRATIO</value>
<minimum>0.75</minimum>
</limit>
<limit>
<counter>COMPLEXITY</counter>
<value>COVEREDRATIO</value>
<minimum>0.75</minimum>
</limit>
<limit>
<counter>METHOD</counter>
<value>COVEREDRATIO</value>
<minimum>0.75</minimum>
</limit>
<limit>
<counter>CLASS</counter>
<value>COVEREDRATIO</value>
<minimum>0.75</minimum>
</limit>

<limit>
<counter>INSTRUCTION</counter>
<value>COVEREDRATIO</value>
<minimum>0.75</minimum>
</limit>
<limit>
<counter>BRANCH</counter>
<value>COVEREDRATIO</value>
<minimum>0.75</minimum>
</limit>
</limits>
<excludes>
<exclude>com.greenfoxacademy.backend.models.*</exclude>
<exclude>com.greenfoxacademy.backend.BackendApplication</exclude>
</excludes>
</rule>
</rules>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
</build>

<reporting>
<plugins>
<plugin>
<groupId>org.jacoco</groupId>
<artifactId>jacoco-maven-plugin</artifactId>
<version>0.8.12</version>
<reportSets>
<reportSet>
<reports>
<report>report</report>
</reports>
</reportSet>
</reportSets>
</plugin>
</plugins>
</reporting>
</project>
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package com.greenfoxacademy.backend.config;

import lombok.Data;
import lombok.Getter;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Configuration;

Expand All @@ -9,7 +10,7 @@
*/

@Configuration
@Data
@Getter
public class JwtConfig {
@Value("${jwt.expiration-time}")
private Long expirationTime;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,5 +21,7 @@ public interface UserService extends UserDetailsService {
LoginResponseDto login(LoginRequestDto loginRequestDto) throws Exception;

ProfileUpdateResponseDto profileUpdate(
String user, ProfileUpdateRequestDto profileUpdateRequestDto) throws Exception;
String user,
ProfileUpdateRequestDto profileUpdateRequestDto
) throws Exception;
}
Original file line number Diff line number Diff line change
Expand Up @@ -27,15 +27,17 @@ public class UserServiceImpl implements UserService {
private final AuthService authService;

@Override
public RegisterResponseDto register(
RegisterRequestDto registerRequestDto) throws UserAlreadyExistsError {
public RegisterResponseDto register(RegisterRequestDto registerRequestDto)
throws UserAlreadyExistsError {

// @formatter:off
User user = User.builder()
.email(registerRequestDto.email())
.firstName(registerRequestDto.firstName())
.lastName(registerRequestDto.lastName())
.password(passwordEncoder.encode(registerRequestDto.password()))
.build();
// @formatter:on
try {
return new RegisterResponseDto(userRepository.save(user).getId());
} catch (Exception e) {
Expand All @@ -45,10 +47,9 @@ public RegisterResponseDto register(


@Override
public LoginResponseDto login(
LoginRequestDto loginRequestDto) throws Exception {
User user = userRepository
.findByEmail(loginRequestDto.email()).orElseThrow(() -> new Exception("User not found"));
public LoginResponseDto login(LoginRequestDto loginRequestDto) throws Exception {
User user = userRepository.findByEmail(loginRequestDto.email())
.orElseThrow(() -> new Exception("User not found"));
if (!passwordEncoder.matches(loginRequestDto.password(), user.getPassword())) {
throw new Exception("Invalid password");
}
Expand All @@ -57,9 +58,14 @@ public LoginResponseDto login(

@Override
public ProfileUpdateResponseDto profileUpdate(
String email, ProfileUpdateRequestDto profileUpdateRequestDto) throws Exception {
User user = userRepository
.findByEmail(email).orElseThrow(() -> new UsernameNotFoundException("User not found"));
String email,
ProfileUpdateRequestDto profileUpdateRequestDto
) {
User user = userRepository.findByEmail(email)
.orElseThrow(() -> new UsernameNotFoundException("User not found"));
if (userRepository.existsByEmail(profileUpdateRequestDto.email())) {
throw new UserAlreadyExistsError("Email is already taken!");
}
user.setEmail(profileUpdateRequestDto.email());
user.setFirstName(profileUpdateRequestDto.firstName());
user.setLastName(profileUpdateRequestDto.lastName());
Expand All @@ -71,7 +77,7 @@ public ProfileUpdateResponseDto profileUpdate(

@Override
public UserDetails loadUserByUsername(String username) throws UsernameNotFoundException {
return userRepository
.findByEmail(username).orElseThrow(() -> new UsernameNotFoundException("No such user!"));
return userRepository.findByEmail(username)
.orElseThrow(() -> new UsernameNotFoundException("No such user!"));
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
package com.greenfoxacademy.backend.config;

import static org.junit.jupiter.api.Assertions.assertEquals;

import org.junit.jupiter.api.Test;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.context.SpringBootTest;


@SpringBootTest
class JwtConfigTest {

@Autowired
private JwtConfig jwtConfig = new JwtConfig();

@Test
void getExpirationTime() {
assertEquals(86400000, jwtConfig.getExpirationTime());
}
}
Loading
Loading