diff --git a/.github/workflows/backend.yml b/.github/workflows/backend.yml new file mode 100644 index 0000000..c479308 --- /dev/null +++ b/.github/workflows/backend.yml @@ -0,0 +1,36 @@ +name: Backend CI + +on: + push: + branches: [main] + paths: + - "backend/**" + + pull_request: + branches: [main] + paths: + - "backend/**" + +jobs: + backend: + runs-on: ubuntu-latest + + defaults: + run: + working-directory: backend + + steps: + - uses: actions/checkout@v4 + + - uses: actions/setup-java@v5 + with: + distribution: temurin + java-version: "21" + cache: maven + cache-dependency-path: backend/pom.xml + + - name: Make Maven Wrapper executable + run: chmod +x mvnw + + - name: Run backend tests + run: ./mvnw -q clean test diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml deleted file mode 100644 index d8aaf2b..0000000 --- a/.github/workflows/ci.yml +++ /dev/null @@ -1,58 +0,0 @@ -name: CI - -on: - push: - branches: [main] - pull_request: - branches: [main] - -jobs: - backend: - name: Backend - runs-on: ubuntu-latest - - defaults: - run: - working-directory: backend - - steps: - - uses: actions/checkout@v4 - - - uses: actions/setup-java@v4 - with: - distribution: temurin - java-version: "21" - cache: maven - - - name: Make Maven Wrapper executable - run: chmod +x mvnw - - - name: Verify backend builds - run: ./mvnw -q clean test - - frontend: - name: Frontend - runs-on: ubuntu-latest - - defaults: - run: - working-directory: frontend - - steps: - - uses: actions/checkout@v4 - - - uses: actions/setup-java@v5 - with: - distribution: temurin - java-version: "21" - cache: maven - cache-dependency-path: backend/pom.xml - - - name: Install dependencies - run: npm ci - - - name: Build frontend - run: npm run build - - - name: Run frontend tests (headless) - run: npm test -- --watch=false --browsers=ChromeHeadless diff --git a/.github/workflows/frontend.yml b/.github/workflows/frontend.yml new file mode 100644 index 0000000..b4d9503 --- /dev/null +++ b/.github/workflows/frontend.yml @@ -0,0 +1,38 @@ +name: Frontend CI + +on: + push: + branches: [main] + paths: + - "frontend/**" + + pull_request: + branches: [main] + paths: + - "frontend/**" + +jobs: + frontend: + runs-on: ubuntu-latest + + defaults: + run: + working-directory: frontend + + steps: + - uses: actions/checkout@v4 + + - uses: actions/setup-node@v4 + with: + node-version: 22 + cache: npm + cache-dependency-path: frontend/package-lock.json + + - name: Install dependencies + run: npm ci + + - name: Build frontend + run: npm run build + + - name: Run frontend tests + run: npm run test:ci diff --git a/backend/src/main/java/com/zemolibrary/backend/controller/HelloController.java b/backend/src/main/java/com/zemolibrary/backend/controller/HelloController.java new file mode 100644 index 0000000..002234a --- /dev/null +++ b/backend/src/main/java/com/zemolibrary/backend/controller/HelloController.java @@ -0,0 +1,11 @@ +package com.zemolibrary.backend.controller; +import org.springframework.web.bind.annotation.GetMapping; +import org.springframework.web.bind.annotation.RestController; + +@RestController +public class HelloController { + @GetMapping("/hello") + public String hello() { + return "hello"; + } +} diff --git a/backend/src/test/java/com/zemolibrary/backend/BackendApplicationTests.java b/backend/src/test/java/com/zemolibrary/backend/BackendApplicationTests.java index 7a7d237..61c5763 100644 --- a/backend/src/test/java/com/zemolibrary/backend/BackendApplicationTests.java +++ b/backend/src/test/java/com/zemolibrary/backend/BackendApplicationTests.java @@ -2,12 +2,25 @@ import org.junit.jupiter.api.Test; import org.springframework.boot.test.context.SpringBootTest; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.boot.test.autoconfigure.web.servlet.AutoConfigureMockMvc; +import org.springframework.test.web.servlet.MockMvc; +import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.get; +import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status; +import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.content; @SpringBootTest +@AutoConfigureMockMvc class BackendApplicationTests { + @Autowired + private MockMvc mockMvc; @Test void contextLoads() { } + @Test + public void hello() throws Exception { + mockMvc.perform(get("/hello")).andExpect(status().isOk()).andExpect(content().string("hello")); + } } diff --git a/frontend/package.json b/frontend/package.json index d3f8163..165bf72 100644 --- a/frontend/package.json +++ b/frontend/package.json @@ -6,7 +6,8 @@ "start": "ng serve", "build": "ng build", "watch": "ng build --watch --configuration development", - "test": "ng test" + "test": "ng test", + "test:ci": "ng test --watch=false --browsers=ChromeHeadless" }, "prettier": { "printWidth": 100, @@ -45,4 +46,4 @@ "karma-jasmine-html-reporter": "~2.1.0", "typescript": "~5.9.2" } -} \ No newline at end of file +} diff --git a/frontend/src/app/app.spec.ts b/frontend/src/app/app.spec.ts index ee55151..3b826dc 100644 --- a/frontend/src/app/app.spec.ts +++ b/frontend/src/app/app.spec.ts @@ -8,16 +8,13 @@ describe('App', () => { }).compileComponents(); }); - it('should create the app', () => { + it('should create and render the root component', () => { const fixture = TestBed.createComponent(App); - const app = fixture.componentInstance; - expect(app).toBeTruthy(); - }); - it('should render title', () => { - const fixture = TestBed.createComponent(App); + expect(fixture.componentInstance).toBeTruthy(); + fixture.detectChanges(); - const compiled = fixture.nativeElement as HTMLElement; - expect(compiled.querySelector('h1')?.textContent).toContain('Hello, zemolibrary'); + + expect(fixture.nativeElement).toBeTruthy(); }); });