Skip to content

Commit 86a0286

Browse files
authored
merge: Company 통합테스트, 단위테스트 작성
[Feature/web company crud test] Company 통합테스트, 단위테스트 작성
2 parents 8843b51 + 218de6d commit 86a0286

37 files changed

Lines changed: 2265 additions & 411 deletions

File tree

.github/workflows/cicd.yml

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,14 +6,23 @@ on:
66

77
jobs:
88
build:
9+
env:
10+
MYSQL_HOST: localhost
11+
MYSQL_PORT: 3306
12+
MYSQL_DB: charlee
13+
MYSQL_USER: root
14+
MYSQL_PASSWORD: root1234!!
15+
MYSQL_SSL: false
16+
MYSQL_UNICODE: true
17+
MYSQL_KEY: true
918
name: Build
1019
runs-on: ubuntu-latest
1120
services:
1221
mysql:
1322
image: mysql:8.0
1423
env:
1524
MYSQL_ROOT_PASSWORD: root1234!!
16-
MYSQL_DATABASE: test_db
25+
MYSQL_DATABASE: charlee
1726
MYSQL_USER: user
1827
MYSQL_PASSWORD: 1234
1928
ports:

build.gradle

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,7 @@ subprojects {
4646
implementation 'org.springframework.boot:spring-boot-starter-actuator:3.4.3'
4747
runtimeOnly 'org.springframework.cloud:spring-cloud-starter-vault-config'
4848
testImplementation 'org.springframework.boot:spring-boot-starter-test'
49+
testImplementation 'org.springframework.restdocs:spring-restdocs-mockmvc'
4950
testRuntimeOnly 'org.junit.platform:junit-platform-launcher'
5051
}
5152

charlee-web/build.gradle

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,11 @@
1+
plugins {
2+
id 'org.asciidoctor.jvm.convert' version '3.3.2'
3+
}
4+
5+
configurations {
6+
asciidoctorExt
7+
}
8+
19
dependencies {
210
implementation 'org.springframework.boot:spring-boot-starter-web'
311
implementation 'org.springframework.boot:spring-boot-starter-data-jpa'
@@ -14,9 +22,26 @@ dependencies {
1422
annotationProcessor 'org.projectlombok:lombok'
1523
annotationProcessor 'org.springframework.boot:spring-boot-configuration-processor'
1624
implementation 'org.springframework.boot:spring-boot-starter-validation'
25+
26+
testImplementation 'org.springframework.restdocs:spring-restdocs-mockmvc'
1727
testImplementation 'org.springframework.boot:spring-boot-starter-test'
1828
testImplementation 'com.h2database:h2'
1929
testRuntimeOnly 'org.junit.platform:junit-platform-launcher'
30+
asciidoctorExt 'org.springframework.restdocs:spring-restdocs-asciidoctor'
31+
}
32+
33+
asciidoctor {
34+
baseDirFollowsSourceDir()
35+
configurations "asciidoctorExt"
36+
37+
dependsOn test
38+
39+
doLast {
40+
copy {
41+
from file("build/docs/asciidoc")
42+
into file("src/main/resources/static")
43+
}
44+
}
2045
}
2146

2247
bootJar {
Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
== Create Company API
2+
3+
새 업체를 생성합니다.
4+
5+
.Request
6+
include::{snippets}/create-company/http-request.adoc[]
7+
include::{snippets}/create-company/request-fields.adoc[]
8+
9+
.Response
10+
include::{snippets}/create-company/http-response.adoc[]
11+
include::{snippets}/create-company/response-fields.adoc[]
12+
13+
== Get Company API
14+
15+
업체의 상세 정보를 조회합니다.
16+
17+
.Request Body
18+
include::{snippets}/get-company/http-request.adoc[]
19+
include::{snippets}/get-company/path-parameters.adoc[]
20+
21+
.Response Body
22+
include::{snippets}/get-company/http-response.adoc[]
23+
include::{snippets}/get-company/response-fields.adoc[]
24+
25+
== Update Company API
26+
27+
업체의 정보를 수정합니다.
28+
29+
.Request Body
30+
include::{snippets}/update-company/http-request.adoc[]
31+
include::{snippets}/update-company/path-parameters.adoc[]
32+
include::{snippets}/update-company/request-fields.adoc[]
33+
34+
.Response Body
35+
include::{snippets}/update-company/http-response.adoc[]
36+
include::{snippets}/update-company/response-fields.adoc[]
37+
38+
== Delete Company API
39+
40+
업체의 정보를 삭제합니다.
41+
42+
.Request Body
43+
include::{snippets}/delete-company/http-request.adoc[]
44+
include::{snippets}/delete-company/path-parameters.adoc[]
45+
46+
.Response Body
47+
include::{snippets}/delete-company/http-response.adoc[]
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
== API List
2+
3+
include::company.adoc[]

charlee-web/src/main/java/com/efa73/charleeweb/CharleeWebApplication.java

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,5 +13,4 @@ public class CharleeWebApplication {
1313
public static void main(String[] args) {
1414
SpringApplication.run(CharleeWebApplication.class, args);
1515
}
16-
1716
}

charlee-web/src/main/java/com/efa73/charleeweb/user/domain/entity/User.java renamed to charlee-web/src/main/java/com/efa73/charleeweb/account/domain/entity/Account.java

Lines changed: 14 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
package com.efa73.charleeweb.user.domain.entity;
1+
package com.efa73.charleeweb.account.domain.entity;
22

33
import com.efa73.charleeweb.common.Common;
44
import jakarta.persistence.Column;
@@ -13,40 +13,38 @@
1313
import lombok.Getter;
1414
import lombok.NoArgsConstructor;
1515

16+
@Entity
17+
@Table(name = "account")
1618
@Getter
17-
@Table(name = "\"user\"") //TODO: 테스트 통과하기 위해 임시로 추가
1819
@NoArgsConstructor(access = AccessLevel.PROTECTED)
19-
@Entity
20-
public class User extends Common {
20+
public class Account extends Common {
2121

2222
@Id
2323
@GeneratedValue(strategy = GenerationType.IDENTITY)
2424
private Long id;
2525

26-
@Column(nullable = false)
27-
private String name;
28-
29-
@Column(nullable = false)
26+
@Column(nullable = false, unique = true)
3027
private String email;
3128

3229
@Column(nullable = false)
3330
private String password;
3431

35-
private String phone;
36-
3732
@Column(nullable = false)
3833
@Enumerated(EnumType.STRING)
3934
private Role role;
4035

41-
public static User of(String name, String email, String password, String phone, Role role) {
42-
return new User(name, email, password, phone, role);
36+
private Account(String email, String password, Role role) {
37+
this.email = email;
38+
this.password = password;
39+
this.role = role;
4340
}
4441

45-
private User(String name, String email, String password, String phone, Role role) {
46-
this.name = name;
42+
public static Account createEntity(String email, String password, Role role) {
43+
return new Account(email, password, role);
44+
}
45+
46+
public void updateEntity(String email, String password) {
4747
this.email = email;
4848
this.password = password;
49-
this.phone = phone;
50-
this.role = role;
5149
}
5250
}
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
package com.efa73.charleeweb.account.domain.entity;
2+
3+
public enum Role {
4+
ADMIN, COMPANY
5+
}
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
package com.efa73.charleeweb.account.domain.repository;
2+
3+
import com.efa73.charleeweb.account.domain.entity.Account;
4+
import com.efa73.charleeweb.account.domain.entity.Role;
5+
import org.springframework.data.jpa.repository.JpaRepository;
6+
import org.springframework.stereotype.Repository;
7+
8+
@Repository
9+
public interface AccountRepository extends JpaRepository<Account, Long> {
10+
11+
boolean existsByRole(Role role);
12+
13+
boolean existsByEmail(String email);
14+
}
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
package com.efa73.charleeweb.account.domain.service;
2+
3+
import com.efa73.charleeweb.account.domain.entity.Account;
4+
import com.efa73.charleeweb.account.domain.entity.Role;
5+
import com.efa73.charleeweb.account.domain.repository.AccountRepository;
6+
import com.efa73.charleeweb.common.exception.CharleeException;
7+
import com.efa73.charleeweb.common.exception.CommonErrorCode;
8+
import lombok.RequiredArgsConstructor;
9+
import org.springframework.stereotype.Service;
10+
11+
@Service
12+
@RequiredArgsConstructor
13+
public class AccountService {
14+
15+
private final AccountRepository accountRepository;
16+
17+
public Account create(String email, String password, Role role) {
18+
existsByEmail(email);
19+
Account account = Account.createEntity(email, password, role);
20+
21+
return accountRepository.save(account);
22+
}
23+
24+
private void existsByEmail(String email) {
25+
if (accountRepository.existsByEmail(email)) {
26+
throw new CharleeException(CommonErrorCode.EMAIL_ALREADY_EXISTS);
27+
}
28+
}
29+
}

0 commit comments

Comments
 (0)