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

Implementação de Análise e Teste de Código no Sonar Cloud #7

Merged
merged 5 commits into from
Jan 9, 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
4 changes: 2 additions & 2 deletions .github/workflows/build_and_test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
17 changes: 7 additions & 10 deletions HomeBrokerSPA/Dockerfile-Development
Original file line number Diff line number Diff line change
@@ -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 . .
Expand All @@ -15,13 +9,16 @@ RUN apt-get update && \
apt-get install -y nodejs
RUN npm install -g [email protected] && \
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"]
19 changes: 8 additions & 11 deletions HomeBrokerSPA/Dockerfile-Production
Original file line number Diff line number Diff line change
@@ -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 . .
Expand All @@ -15,13 +9,16 @@ RUN apt-get update && \
apt-get install -y nodejs
RUN npm install -g [email protected] && \
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"]
EXPOSE 44538
ENV ASPNETCORE_ENVIRONMENT=Production
ENV ASPNETCORE_URLS=http://+:44538

COPY --from=build /app/publish .
ENTRYPOINT ["dotnet", "HomeBrokerSPA.dll"]
Original file line number Diff line number Diff line change
@@ -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<NavMenuComponent>;

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();
});
});
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
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<HomeComponent>;
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();
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -8,15 +8,16 @@ import * as dayjs from 'dayjs';
})
export class HomeComponent {
public magazineLuizaHistoryPrices?: MagazineLuizaHistoryPrice[];
period: Period;

constructor(public chartService: ChartService) { }

async ngOnInit(): Promise<void> {
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';
}
2 changes: 1 addition & 1 deletion docker-compose.dcproj
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
<DockerTargetOS>Linux</DockerTargetOS>
<ProjectGuid>9e1011b3-211b-4acf-ad4b-cd7e6be248bd</ProjectGuid>
<DockerLaunchAction>LaunchBrowser</DockerLaunchAction>
<DockerServiceUrl>{Scheme}://localhost:{ServicePort}/index.html</DockerServiceUrl>
<DockerServiceUrl>{Scheme}://localhost:{ServicePort}</DockerServiceUrl>
<DockerServiceName>homebrokerspa</DockerServiceName>
</PropertyGroup>
<ItemGroup>
Expand Down
7 changes: 6 additions & 1 deletion slnHomeBroker.sln
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -61,7 +67,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
Expand Down