Skip to content
Open
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
121 changes: 121 additions & 0 deletions .github/workflows/ci-optimized.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,121 @@
name: CI

on:
push:
branches: [main]

jobs:
backend-OPTIMIZED:
name: Backend - OPTIMIZED
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4

- name: Setup .NET
uses: actions/setup-dotnet@v4
with:
dotnet-version: '8.0.x'

- name: Cache NuGet packages
uses: actions/cache@v4
with:
path: ~/.nuget/packages
key: ${{ runner.os }}-nuget-${{ hashFiles('lab5/sample-ci/backend/**/*.csproj') }}

- name: Restore dependencies
run: |
cd lab5/sample-ci/backend/ProductApi
dotnet restore

- name: Restore dependencies
run: |
cd lab5/sample-ci/backend/ProductApi
dotnet restore
cd ../ProductApi.Tests
dotnet restore

- name: Build
run: |
cd lab5/sample-ci/backend/ProductApi
dotnet build --no-restore --configuration Release
cd ../ProductApi.Tests
dotnet build --no-restore --configuration Release

- name: Restore dependencies
run: |
cd lab5/sample-ci/backend/ProductApi
dotnet restore
cd ../ProductApi.Tests
dotnet restore

- name: Build
run: |
cd lab5/sample-ci/backend/ProductApi
dotnet build --configuration Release
cd ../ProductApi.Tests
dotnet build --configuration Release

- name: Test
run: |
cd lab5/sample-ci/backend/ProductApi.Tests
dotnet test --no-build --configuration Release --logger trx

- name: Restore dependencies
run: |
cd lab5/sample-ci/backend/ProductApi
dotnet restore

- name: Build
run: |
cd lab5/sample-ci/backend/ProductApi
dotnet build --configuration Release

- name: Publish
run: |
cd lab5/sample-ci/backend/ProductApi
dotnet publish --no-build --configuration Release --output ./publish

- name: Upload artifacts
uses: actions/upload-artifact@v4
with:
name: backend
path: lab5/sample-ci/backend/ProductApi/publish

frontend-OPTIMIZED:
name: Frontend - OPTIMIZED
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4

- name: Setup Node.js
uses: actions/setup-node@v4
with:
node-version: '20'
cache: 'npm'
cache-dependency-path: lab5/sample-ci/frontend/package-lock.json

- name: Install dependencies
run: |
cd lab5/sample-ci/frontend
npm ci

- name: Run tests
run: |
cd lab5/sample-ci/frontend
npm test

- name: Install dependencies
run: |
cd lab5/sample-ci/frontend
npm ci

- name: Build
run: |
cd lab5/sample-ci/frontend
npm run build

- name: Upload artifacts
uses: actions/upload-artifact@v4
with:
name: frontend
path: lab5/sample-ci/frontend/dist
Binary file modified lab5/sample-ci/README.md
Binary file not shown.
96 changes: 50 additions & 46 deletions lab5/sample-ci/frontend/app.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,53 +3,57 @@
*/

describe('Product Manager App', () => {
test('displayProducts should render products correctly', () => {
// Setup
document.body.innerHTML = '<div id="products"></div>';

const products = [
{ name: 'Laptop', price: 999.99 },
{ name: 'Mouse', price: 29.99 }
];

// Mock the displayProducts function
const displayProducts = (products) => {
const container = document.getElementById('products');
container.innerHTML = products.map(product => `
test('displayProducts should render products correctly', () => {
// Setup
document.body.innerHTML = '<div id="products"></div>';

const products = [
{ name: 'Laptop', price: 999.99 },
{ name: 'Mouse', price: 29.99 },
];

// Mock the displayProducts function 123
const displayProducts = (products) => {
const container = document.getElementById('products');
container.innerHTML = products
.map(
(product) => `
<div class="product-item">
<strong>${product.name}</strong> - $${product.price.toFixed(2)}
</div>
`).join('');
};

// Execute
displayProducts(products);

// Assert
const container = document.getElementById('products');
expect(container.innerHTML).toContain('Laptop');
expect(container.innerHTML).toContain('999.99');
expect(container.innerHTML).toContain('Mouse');
expect(container.innerHTML).toContain('29.99');
});

test('displayProducts should show message when no products', () => {
// Setup
document.body.innerHTML = '<div id="products"></div>';

const displayProducts = (products) => {
const container = document.getElementById('products');
if (products.length === 0) {
container.innerHTML = '<p>No products found</p>';
return;
}
};

// Execute
displayProducts([]);

// Assert
const container = document.getElementById('products');
expect(container.innerHTML).toContain('No products found');
});
`,
)
.join('');
};

// Execute
displayProducts(products);

// Assert
const container = document.getElementById('products');
expect(container.innerHTML).toContain('Laptop');
expect(container.innerHTML).toContain('999.99');
expect(container.innerHTML).toContain('Mouse');
expect(container.innerHTML).toContain('29.99');
});

test('displayProducts should show message when no products', () => {
// Setup
document.body.innerHTML = '<div id="products"></div>';

const displayProducts = (products) => {
const container = document.getElementById('products');
if (products.length === 0) {
container.innerHTML = '<p>No products found</p>';
return;
}
};

// Execute
displayProducts([]);

// Assert
const container = document.getElementById('products');
expect(container.innerHTML).toContain('No products found');
});
});
54 changes: 54 additions & 0 deletions wsei-devops-lab.sln
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
Microsoft Visual Studio Solution File, Format Version 12.00
# Visual Studio Version 17
VisualStudioVersion = 17.5.2.0
MinimumVisualStudioVersion = 10.0.40219.1
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "lab4", "lab4", "{A27D918D-BA35-9B07-9085-4B619D49ED1B}"
EndProject
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "lab5", "lab5", "{AFD2E28E-1813-3585-10F3-95D964F36B3C}"
EndProject
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "sample-app", "sample-app", "{F5248CE3-9565-C979-BEF7-A818B491119D}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "ProductApi", "lab4\sample-app\backend\ProductApi.csproj", "{84B9459D-D57A-011B-B83E-95CC8140E916}"
EndProject
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "sample-ci", "sample-ci", "{5983FE21-479C-8180-15DB-8A55AC04F830}"
EndProject
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "backend", "backend", "{B3CCC773-FFE8-F282-F523-078F1052BE2D}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "ProductApi", "lab5\sample-ci\backend\ProductApi\ProductApi.csproj", "{C49D7C6D-BD21-F7F2-B8B1-3BB4AD4827EF}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "ProductApi.Tests", "lab5\sample-ci\backend\ProductApi.Tests\ProductApi.Tests.csproj", "{80C55723-0F46-F848-3385-FF460C4C00F0}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Release|Any CPU = Release|Any CPU
EndGlobalSection
GlobalSection(ProjectConfigurationPlatforms) = postSolution
{84B9459D-D57A-011B-B83E-95CC8140E916}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{84B9459D-D57A-011B-B83E-95CC8140E916}.Debug|Any CPU.Build.0 = Debug|Any CPU
{84B9459D-D57A-011B-B83E-95CC8140E916}.Release|Any CPU.ActiveCfg = Release|Any CPU
{84B9459D-D57A-011B-B83E-95CC8140E916}.Release|Any CPU.Build.0 = Release|Any CPU
{C49D7C6D-BD21-F7F2-B8B1-3BB4AD4827EF}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{C49D7C6D-BD21-F7F2-B8B1-3BB4AD4827EF}.Debug|Any CPU.Build.0 = Debug|Any CPU
{C49D7C6D-BD21-F7F2-B8B1-3BB4AD4827EF}.Release|Any CPU.ActiveCfg = Release|Any CPU
{C49D7C6D-BD21-F7F2-B8B1-3BB4AD4827EF}.Release|Any CPU.Build.0 = Release|Any CPU
{80C55723-0F46-F848-3385-FF460C4C00F0}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{80C55723-0F46-F848-3385-FF460C4C00F0}.Debug|Any CPU.Build.0 = Debug|Any CPU
{80C55723-0F46-F848-3385-FF460C4C00F0}.Release|Any CPU.ActiveCfg = Release|Any CPU
{80C55723-0F46-F848-3385-FF460C4C00F0}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
EndGlobalSection
GlobalSection(NestedProjects) = preSolution
{F5248CE3-9565-C979-BEF7-A818B491119D} = {A27D918D-BA35-9B07-9085-4B619D49ED1B}
{84B9459D-D57A-011B-B83E-95CC8140E916} = {F5248CE3-9565-C979-BEF7-A818B491119D}
{5983FE21-479C-8180-15DB-8A55AC04F830} = {AFD2E28E-1813-3585-10F3-95D964F36B3C}
{B3CCC773-FFE8-F282-F523-078F1052BE2D} = {5983FE21-479C-8180-15DB-8A55AC04F830}
{C49D7C6D-BD21-F7F2-B8B1-3BB4AD4827EF} = {B3CCC773-FFE8-F282-F523-078F1052BE2D}
{80C55723-0F46-F848-3385-FF460C4C00F0} = {B3CCC773-FFE8-F282-F523-078F1052BE2D}
EndGlobalSection
GlobalSection(ExtensibilityGlobals) = postSolution
SolutionGuid = {3A47BC0B-7CAF-49F2-999B-CC44C196317F}
EndGlobalSection
EndGlobal