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

Feature#307 #371

Merged
merged 27 commits into from
Jun 11, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
27 commits
Select commit Hold shift + click to select a range
80c5103
Implementa OnInit en StarterComponent para manejo del ciclo de vida d…
Yul1b3th Jun 5, 2024
cfbefe9
Refactorización del servicio StarterService
Yul1b3th Jun 6, 2024
3ed0144
Refactorización del servicio StarterService
Yul1b3th Jun 6, 2024
96e4f32
Realizadas pruebas unitarias para el servicio StarterService en start…
Yul1b3th Jun 6, 2024
ad8187c
changes
Yul1b3th Jun 6, 2024
a236b29
changes
Yul1b3th Jun 6, 2024
e1f3d3c
Realizadas pruebas unitarias al componente StarterComponent
Yul1b3th Jun 6, 2024
7725bf0
Elimina la llamada a getAllChallenges en StarterComponent
Yul1b3th Jun 6, 2024
c05cb87
Solucionar los errores de ESLINT y TEST de auth.service.ts y auth.ser…
codenaud Jun 10, 2024
9939065
Resolved merge conflicts between feature#307 and feature#307a - comen…
codenaud Jun 10, 2024
4738300
Solventar Sonar cloud problema con password: 'testPassword'
codenaud Jun 10, 2024
f6536f5
Nueva alternativa fallos SonarCloud credenciales de password 'hardcod…
codenaud Jun 10, 2024
a398478
changes
Yul1b3th Jun 10, 2024
10e072e
Merge branch 'feature#307y' into feature#307
Yul1b3th Jun 10, 2024
bfb2cef
Implementa OnInit en StarterComponent para manejo del ciclo de vida d…
Yul1b3th Jun 5, 2024
650cc15
Refactorización del servicio StarterService
Yul1b3th Jun 6, 2024
5a89453
Refactorización del servicio StarterService
Yul1b3th Jun 6, 2024
c6390c2
Realizadas pruebas unitarias para el servicio StarterService en start…
Yul1b3th Jun 6, 2024
45452b9
changes
Yul1b3th Jun 6, 2024
5345026
changes
Yul1b3th Jun 6, 2024
9550999
Realizadas pruebas unitarias al componente StarterComponent
Yul1b3th Jun 6, 2024
94ed2dd
Elimina la llamada a getAllChallenges en StarterComponent
Yul1b3th Jun 6, 2024
ff5f6e4
Solventar Sonar cloud problema con password: 'testPassword'
codenaud Jun 10, 2024
eb3cb21
Nueva alternativa fallos SonarCloud credenciales de password 'hardcod…
codenaud Jun 10, 2024
c0f284c
changes
Yul1b3th Jun 10, 2024
c779fa3
Commit de los cambios locales en feature#307y
Yul1b3th Jun 11, 2024
72c037c
Merge branch 'feature#307' of https://github.com/IT-Academy-BCN/ita-c…
Yul1b3th Jun 11, 2024
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 .eslintignore
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
src/app/services/starter.service.*
src/app/services/auth.service.*
# src/app/services/starter.service.*
# src/app/services/auth.service.*
4 changes: 2 additions & 2 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,14 @@ import { StarterService } from 'src/app/services/starter.service'
import { TranslateModule } from '@ngx-translate/core'

import { HttpClientTestingModule, HttpTestingController } from '@angular/common/http/testing'
import { environment } from 'src/environments/environment'
import { of } from 'rxjs'
import { environment } from 'src/environments/environment'

describe('StarterComponent', () => {
let component: StarterComponent
let fixture: ComponentFixture<StarterComponent>
let starterService: StarterService
let httpClientMock: HttpTestingController
let httpMock: HttpTestingController

beforeEach(() => {
TestBed.configureTestingModule({
Expand All @@ -23,7 +23,7 @@ describe('StarterComponent', () => {
component = fixture.componentInstance
fixture.detectChanges()
starterService = TestBed.inject(StarterService)
httpClientMock = TestBed.inject(HttpTestingController)
httpMock = TestBed.inject(HttpTestingController)
})

it('should create', () => {
Expand All @@ -40,26 +40,6 @@ describe('StarterComponent', () => {
done()
})

it('should call getAllChallengesOffset when sortBy empty', (done) => {
const mockResponse = { challenge: 'challenge' }
const starterServiceSpy = jest.spyOn(starterService, 'getAllChallengesOffset').mockReturnValue(of(mockResponse))
component.sortBy = ''

component.getChallengesByPage(1)

const req = httpClientMock.expectOne(`${environment.BACKEND_ITA_CHALLENGE_BASE_URL}${environment.BACKEND_ALL_CHALLENGES_URL}?offset=0&limit=8`)
expect(req.request.method).toEqual('GET')

expect(starterServiceSpy).toBeCalledWith(0, 8)
expect(component.listChallenges).toBe(mockResponse)
expect(component.totalPages).toEqual(3)
expect(starterService.getAllChallengesOffset).toHaveBeenCalled()

req.flush(mockResponse)
httpClientMock.verify()
done()
})

it('should set listChallenges correctly when sortBy is empty', () => {
const mockResponse = { challenge: 'challenge' }
spyOn(starterService, 'getAllChallengesOffset').and.returnValue(of(mockResponse))
Expand Down Expand Up @@ -127,4 +107,18 @@ describe('StarterComponent', () => {

expect(getChallengeFiltersSpy).toHaveBeenCalled()
})

it('should call getAllChallengesOffset with correct parameters', () => {
const mockChallenges = [{ id: 1, name: 'Test Challenge' }]
const pageOffset = 0
const pageLimit = 10

starterService.getAllChallengesOffset(pageOffset, pageLimit).subscribe((challenges: any) => {
expect(challenges).toEqual(mockChallenges)
})

const req = httpMock.expectOne(`${environment.BACKEND_ITA_CHALLENGE_BASE_URL}${environment.BACKEND_ALL_CHALLENGES_URL}?offset=${pageOffset}&limit=${pageLimit}`)
expect(req.request.method).toBe('GET')
req.flush(mockChallenges)
})
})
20 changes: 12 additions & 8 deletions src/app/modules/starter/components/starter/starter.component.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { type FilterChallenge } from './../../../../models/filter-challenge.model'
import { Component, Inject, ViewChild } from '@angular/core'
import { Component, Inject, type OnInit, ViewChild } from '@angular/core'
import { type Subscription } from 'rxjs'
import { StarterService } from '../../../../services/starter.service'
import { Challenge } from '../../../../models/challenge.model'
Expand All @@ -13,7 +13,7 @@ import { TranslateService } from '@ngx-translate/core'
styleUrls: ['./starter.component.scss'],
providers: []
})
export class StarterComponent {
export class StarterComponent implements OnInit {
@ViewChild('modal') private readonly modalContent!: FiltersModalComponent

challenges: Challenge[] = []
Expand Down Expand Up @@ -76,7 +76,7 @@ export class StarterComponent {
}

private getAndSortChallenges (getChallengeOffset: number, resp: any): void {
const respArray: any[] = Array.isArray(resp) ? resp : [resp]
const respArray: Challenge[] = Array.isArray(resp) ? resp : [resp]
const sortedChallenges$ = this.isAscending
? this.starterService.orderBySortAscending(this.sortBy, respArray, getChallengeOffset, this.pageSize)
: this.starterService.orderBySortAsDescending(this.sortBy, respArray, getChallengeOffset, this.pageSize)
Expand All @@ -99,13 +99,17 @@ export class StarterComponent {
if ((this.filters.languages.length > 0 && this.filters.languages.length < 4) || (this.filters.levels.length > 0 && this.filters.levels.length < 3) || (this.filters.progress.length > 0 && this.filters.progress.length < 3)) {
const respArray: Challenge[] = Array.isArray(resp) ? resp : [resp]
this.starterService.getAllChallengesFiltered(this.filters, respArray)
.subscribe(filteredResp => {
.subscribe((filteredResp: Challenge[]) => {
if (this.sortBy !== '') {
const orderBySortFunction = this.isAscending ? this.starterService.orderBySortAscending : this.starterService.orderBySortAsDescending
orderBySortFunction(this.sortBy, filteredResp, getChallengeOffset, this.pageSize).subscribe(sortedResp => {
this.listChallenges = sortedResp
this.totalPages = Math.ceil(filteredResp.length / this.pageSize)
})
if (filteredResp.every(item => item instanceof Challenge)) {
orderBySortFunction(this.sortBy, filteredResp, getChallengeOffset, this.pageSize).subscribe(sortedResp => {
this.listChallenges = sortedResp
this.totalPages = Math.ceil(filteredResp.length / this.pageSize)
})
} else {
console.error('filteredResp no es un array de Challenge')
}
} else {
this.listChallenges = filteredResp.slice(getChallengeOffset, getChallengeOffset + this.pageSize)
this.totalPages = Math.ceil(filteredResp.length / this.pageSize)
Expand Down
Loading