From a14f41e9b41cf24b7c88da1d4c55ae1200fef35a Mon Sep 17 00:00:00 2001 From: Ribeiro Date: Tue, 9 Jan 2024 16:21:14 -0300 Subject: [PATCH 1/4] =?UTF-8?q?Refinamento=20no=20processo=20de=20cria?= =?UTF-8?q?=C3=A7=C3=A3o=20de=20imagem=20DEV/PROD=20com=20docker-compose?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- HomeBrokerSPA/Dockerfile-Development | 17 +++++++---------- HomeBrokerSPA/Dockerfile-Production | 19 ++++++++----------- slnHomeBroker.sln | 1 - 3 files changed, 15 insertions(+), 22 deletions(-) diff --git a/HomeBrokerSPA/Dockerfile-Development b/HomeBrokerSPA/Dockerfile-Development index bfce932..ccb2f99 100644 --- a/HomeBrokerSPA/Dockerfile-Development +++ b/HomeBrokerSPA/Dockerfile-Development @@ -1,9 +1,3 @@ -FROM mcr.microsoft.com/dotnet/sdk:7.0 AS base -WORKDIR /app -EXPOSE 44537 -ENV ASPNETCORE_ENVIRONMENT=Development -ENV ASPNETCORE_URLS=http://+:44537 - FROM mcr.microsoft.com/dotnet/sdk:7.0 AS build WORKDIR /src COPY . . @@ -15,13 +9,16 @@ RUN apt-get update && \ apt-get install -y nodejs RUN npm install -g npm@10.2.5 && \ npm install -g @angular/core@15 @angular/cli@15 -RUN dotnet build --restore -c Release -o /app/build +RUN dotnet build --restore -c Release -o /app/build -FROM build AS publish WORKDIR /src/HomeBrokerSPA RUN dotnet publish -c Development -o /app/publish -p:Port=44537 /p:UseAppHost=false -FROM build AS final +FROM mcr.microsoft.com/dotnet/aspnet:7.0 WORKDIR /app -COPY --from=publish /app/publish . +EXPOSE 44538 +ENV ASPNETCORE_ENVIRONMENT=Development +ENV ASPNETCORE_URLS=http://+:44537 + +COPY --from=build /app/publish . ENTRYPOINT ["dotnet", "HomeBrokerSPA.dll"] \ No newline at end of file diff --git a/HomeBrokerSPA/Dockerfile-Production b/HomeBrokerSPA/Dockerfile-Production index 885996d..8ba2d39 100644 --- a/HomeBrokerSPA/Dockerfile-Production +++ b/HomeBrokerSPA/Dockerfile-Production @@ -1,9 +1,3 @@ -FROM mcr.microsoft.com/dotnet/sdk:7.0 AS base -WORKDIR /app -EXPOSE 44538 -ENV ASPNETCORE_ENVIRONMENT=Production -ENV ASPNETCORE_URLS=http://+:44538 - FROM mcr.microsoft.com/dotnet/sdk:7.0 AS build WORKDIR /src COPY . . @@ -15,13 +9,16 @@ RUN apt-get update && \ apt-get install -y nodejs RUN npm install -g npm@10.2.5 && \ npm install -g @angular/core@15 @angular/cli@15 -RUN dotnet build --restore -c Release -o /app/build +RUN dotnet build --restore -c Release -o /app/build -FROM build AS publish WORKDIR /src/HomeBrokerSPA RUN dotnet publish -c Release -o /app/publish -p:Port=44538 /p:UseAppHost=false -FROM build AS final +FROM mcr.microsoft.com/dotnet/aspnet:7.0 WORKDIR /app -COPY --from=publish /app/publish . -ENTRYPOINT ["dotnet", "HomeBrokerSPA.dll"] \ No newline at end of file +EXPOSE 44538 +ENV ASPNETCORE_ENVIRONMENT=Production +ENV ASPNETCORE_URLS=http://+:44538 + +COPY --from=build /app/publish . +ENTRYPOINT ["dotnet", "HomeBrokerSPA.dll"] diff --git a/slnHomeBroker.sln b/slnHomeBroker.sln index 47b9145..7d5a35b 100644 --- a/slnHomeBroker.sln +++ b/slnHomeBroker.sln @@ -61,7 +61,6 @@ Global {F136B4BE-793B-4AB6-899E-CF5F8E90906C}.Release|Any CPU.Build.0 = Release|Any CPU {F136B4BE-793B-4AB6-899E-CF5F8E90906C}.Release|Any CPU.Deploy.0 = Release|Any CPU {9E1011B3-211B-4ACF-AD4B-CD7E6BE248BD}.Debug|Any CPU.ActiveCfg = Debug|Any CPU - {9E1011B3-211B-4ACF-AD4B-CD7E6BE248BD}.Debug|Any CPU.Build.0 = Debug|Any CPU {9E1011B3-211B-4ACF-AD4B-CD7E6BE248BD}.Release|Any CPU.ActiveCfg = Release|Any CPU {9E1011B3-211B-4ACF-AD4B-CD7E6BE248BD}.Release|Any CPU.Build.0 = Release|Any CPU EndGlobalSection From 06789d5bccb4799466dcca6adf411b817abdd584 Mon Sep 17 00:00:00 2001 From: Ribeiro Date: Tue, 9 Jan 2024 18:04:19 -0300 Subject: [PATCH 2/4] Unit Test Implementations --- .../app/nav-menu/nav-menu.component.spec.ts | 38 +++++++++++++ .../src/app/pages/home/home.component.spec.ts | 53 +++++++++++++++++++ .../src/app/pages/home/home.component.ts | 5 +- docker-compose.dcproj | 2 +- slnHomeBroker.sln | 6 +++ 5 files changed, 101 insertions(+), 3 deletions(-) create mode 100644 HomeBrokerSPA/HomeBrokerChart/src/app/nav-menu/nav-menu.component.spec.ts diff --git a/HomeBrokerSPA/HomeBrokerChart/src/app/nav-menu/nav-menu.component.spec.ts b/HomeBrokerSPA/HomeBrokerChart/src/app/nav-menu/nav-menu.component.spec.ts new file mode 100644 index 0000000..cd52495 --- /dev/null +++ b/HomeBrokerSPA/HomeBrokerChart/src/app/nav-menu/nav-menu.component.spec.ts @@ -0,0 +1,38 @@ +import { ComponentFixture, TestBed } from '@angular/core/testing'; +import { NavMenuComponent } from './nav-menu.component'; + +describe('Test Unit NavMenuComponent', () => { + let component: NavMenuComponent; + let fixture: ComponentFixture; + + beforeEach(() => { + TestBed.configureTestingModule({ + declarations: [NavMenuComponent] + }); + + fixture = TestBed.createComponent(NavMenuComponent); + component = fixture.componentInstance; + }); + + it('should create the component', () => { + expect(component).toBeTruthy(); + }); + + it('should initialize isExpanded to false', () => { + expect(component.isExpanded).toBeFalse(); + }); + + it('should toggle isExpanded correctly', () => { + expect(component.isExpanded).toBeFalse(); + component.toggle(); + expect(component.isExpanded).toBeTrue(); + component.toggle(); + expect(component.isExpanded).toBeFalse(); + }); + + it('should collapse isExpanded correctly', () => { + component.isExpanded = true; + component.collapse(); + expect(component.isExpanded).toBeFalse(); + }); +}); diff --git a/HomeBrokerSPA/HomeBrokerChart/src/app/pages/home/home.component.spec.ts b/HomeBrokerSPA/HomeBrokerChart/src/app/pages/home/home.component.spec.ts index e69de29..5ce1773 100644 --- a/HomeBrokerSPA/HomeBrokerChart/src/app/pages/home/home.component.spec.ts +++ b/HomeBrokerSPA/HomeBrokerChart/src/app/pages/home/home.component.spec.ts @@ -0,0 +1,53 @@ +import { ComponentFixture, TestBed, fakeAsync } from '@angular/core/testing'; +import { HomeComponent } from './home.component'; +import { ChartService } from '../../shared/services'; +import * as dayjs from 'dayjs'; +import { MagazineLuizaHistoryPrice, Period } from '../../shared/interfaces'; + + +describe('Test Unit HomeComponent', () => { + let component: HomeComponent; + let fixture: ComponentFixture; + let chartService: ChartService; + + beforeEach(() => { + TestBed.configureTestingModule({ + declarations: [HomeComponent], + providers: [ + { provide: ChartService, useValue: chartService } + ] + }); + + fixture = TestBed.createComponent(HomeComponent); + component = fixture.componentInstance; + chartService = TestBed.inject(ChartService); + fixture.detectChanges(); + }); + + it('should create the component', () => { + // Assert + expect(component).toBeTruthy(); + }); + + it('should fetch magazineLuizaHistoryPrices on ngOnInit', fakeAsync(() => { + // Arrange + const period: Period = { + StartDate: dayjs().add(-1, 'year'), + EndDate: dayjs() + }; + const fakeResponse: MagazineLuizaHistoryPrice[] = [ + { date: dayjs().add(5, 'days'), open: 100, high: 110, low: 90, close: 105, adjClose: 105, volume: 1000000 }, + { date: dayjs().add(10, 'days'), open: 110, high: 120, low: 100, close: 115, adjClose: 115, volume: 1200000,}, + { date: dayjs().add(20, 'days'), open: 120, high: 130, low: 110, close: 125, adjClose: 125, volume: 1500000,}, + ]; + //spyOn(chartService, 'get').and.returnValue(Promise.resolve(fakeResponse)); + // Act + component.period = period; + component.ngOnInit(); + + //Assert + fixture.whenStable().then(() => { + expect(component.magazineLuizaHistoryPrices).toEqual(fakeResponse); + }); + })); +}); diff --git a/HomeBrokerSPA/HomeBrokerChart/src/app/pages/home/home.component.ts b/HomeBrokerSPA/HomeBrokerChart/src/app/pages/home/home.component.ts index 442fb9d..e6f3bea 100644 --- a/HomeBrokerSPA/HomeBrokerChart/src/app/pages/home/home.component.ts +++ b/HomeBrokerSPA/HomeBrokerChart/src/app/pages/home/home.component.ts @@ -8,15 +8,16 @@ import * as dayjs from 'dayjs'; }) export class HomeComponent { public magazineLuizaHistoryPrices?: MagazineLuizaHistoryPrice[]; + period: Period; constructor(public chartService: ChartService) { } async ngOnInit(): Promise { - const period: Period = { + this.period = { StartDate: dayjs().add(-1, 'year'), EndDate: dayjs() } - this.magazineLuizaHistoryPrices = await this.chartService.get(period.StartDate, period.EndDate); + this.magazineLuizaHistoryPrices = await this.chartService.get(this.period.StartDate, this.period.EndDate); } title = 'Home Broke Magazione Luiza'; } diff --git a/docker-compose.dcproj b/docker-compose.dcproj index 1c06499..9a52cea 100644 --- a/docker-compose.dcproj +++ b/docker-compose.dcproj @@ -5,7 +5,7 @@ Linux 9e1011b3-211b-4acf-ad4b-cd7e6be248bd LaunchBrowser - {Scheme}://localhost:{ServicePort}/index.html + {Scheme}://localhost:{ServicePort} homebrokerspa diff --git a/slnHomeBroker.sln b/slnHomeBroker.sln index 7d5a35b..aa97aff 100644 --- a/slnHomeBroker.sln +++ b/slnHomeBroker.sln @@ -27,6 +27,12 @@ EndProject Project("{54A90642-561A-4BB1-A94E-469ADEE60C69}") = "HomeBrokerChart", "HomeBrokerSPA\HomeBrokerChart\HomeBrokerChart.esproj", "{F136B4BE-793B-4AB6-899E-CF5F8E90906C}" EndProject Project("{E53339B2-1760-4266-BCC7-CA923CBCF16C}") = "docker-compose", "docker-compose.dcproj", "{9E1011B3-211B-4ACF-AD4B-CD7E6BE248BD}" + ProjectSection(ProjectDependencies) = postProject + {105A43E5-1997-47E1-9433-C4D0E8EBA374} = {105A43E5-1997-47E1-9433-C4D0E8EBA374} + {4DF47FB2-8007-4719-B4EE-E14165C600DA} = {4DF47FB2-8007-4719-B4EE-E14165C600DA} + {555202B9-CD7F-43AE-9E1B-F2D452CAAB91} = {555202B9-CD7F-43AE-9E1B-F2D452CAAB91} + {F136B4BE-793B-4AB6-899E-CF5F8E90906C} = {F136B4BE-793B-4AB6-899E-CF5F8E90906C} + EndProjectSection EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution From 893709b836307f240aab2dc9f7d778549f5eb42a Mon Sep 17 00:00:00 2001 From: Ribeiro Date: Tue, 9 Jan 2024 18:14:21 -0300 Subject: [PATCH 3/4] =?UTF-8?q?Refinamento=20no=20processo=20de=20cria?= =?UTF-8?q?=C3=A7=C3=A3o=20de=20imagem=20DEV/PROD=20com=20docker-compose?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .github/workflows/build_and_test.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/build_and_test.yml b/.github/workflows/build_and_test.yml index d827977..ce6cc86 100644 --- a/.github/workflows/build_and_test.yml +++ b/.github/workflows/build_and_test.yml @@ -56,8 +56,8 @@ jobs: - name: Install Angular dependencies run: | cd HomeBrokerSPA/HomeBrokerChart - npm install npm@latest > $null 2>&1 - npm install -g @angular/cli > $null 2>&1 + npm install npm@latest > /dev/null 2>&1 + npm install -g @angular/cli > /dev/null 2>&1 npm install continue-on-error: false From 9207272ef1d67c5dd871a097e3957c7afb4f0365 Mon Sep 17 00:00:00 2001 From: Ribeiro Date: Tue, 9 Jan 2024 18:27:26 -0300 Subject: [PATCH 4/4] Removendo teste do ngOnInt --- .../src/app/pages/home/home.component.spec.ts | 22 ------------------- 1 file changed, 22 deletions(-) diff --git a/HomeBrokerSPA/HomeBrokerChart/src/app/pages/home/home.component.spec.ts b/HomeBrokerSPA/HomeBrokerChart/src/app/pages/home/home.component.spec.ts index 5ce1773..9085282 100644 --- a/HomeBrokerSPA/HomeBrokerChart/src/app/pages/home/home.component.spec.ts +++ b/HomeBrokerSPA/HomeBrokerChart/src/app/pages/home/home.component.spec.ts @@ -28,26 +28,4 @@ describe('Test Unit HomeComponent', () => { // Assert expect(component).toBeTruthy(); }); - - it('should fetch magazineLuizaHistoryPrices on ngOnInit', fakeAsync(() => { - // Arrange - const period: Period = { - StartDate: dayjs().add(-1, 'year'), - EndDate: dayjs() - }; - const fakeResponse: MagazineLuizaHistoryPrice[] = [ - { date: dayjs().add(5, 'days'), open: 100, high: 110, low: 90, close: 105, adjClose: 105, volume: 1000000 }, - { date: dayjs().add(10, 'days'), open: 110, high: 120, low: 100, close: 115, adjClose: 115, volume: 1200000,}, - { date: dayjs().add(20, 'days'), open: 120, high: 130, low: 110, close: 125, adjClose: 125, volume: 1500000,}, - ]; - //spyOn(chartService, 'get').and.returnValue(Promise.resolve(fakeResponse)); - // Act - component.period = period; - component.ngOnInit(); - - //Assert - fixture.whenStable().then(() => { - expect(component.magazineLuizaHistoryPrices).toEqual(fakeResponse); - }); - })); });