diff --git a/client/src/app/instance/store/models/svom-keyword.model.ts b/client/src/app/instance/store/models/svom-keyword.model.ts index 1fabc699b4d1e4374f5b81f3120652615019ac65..d8ca382b519616ac5d2ce54ebec8a5867da8f6c5 100644 --- a/client/src/app/instance/store/models/svom-keyword.model.ts +++ b/client/src/app/instance/store/models/svom-keyword.model.ts @@ -1,6 +1,21 @@ +/** + * This file is part of Anis Client. + * + * @copyright Laboratoire d'Astrophysique de Marseille / CNRS + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + */ + +/** + * Interface for SVOM Keywords. + * + * @interface SvomKeyword + */ + export interface SvomKeyword { data_type: string default: string extension: string name: string -} \ No newline at end of file +} diff --git a/client/src/app/instance/store/services/svom-json-kw.service.ts b/client/src/app/instance/store/services/svom-json-kw.service.ts index 7a990aa7212a49ea99276349219e44b052d3f011..e86072e9d9d94687519559fb8ff638c5dcddc9d4 100644 --- a/client/src/app/instance/store/services/svom-json-kw.service.ts +++ b/client/src/app/instance/store/services/svom-json-kw.service.ts @@ -9,6 +9,8 @@ import { Injectable } from '@angular/core'; import { HttpClient } from '@angular/common/http'; + +import { Observable } from 'rxjs'; import { map } from 'rxjs/operators'; import { AppConfigService } from 'src/app/app-config.service'; @@ -22,7 +24,14 @@ import { SvomKeyword } from '../models'; export class SvomJsonKwService { constructor(private http: HttpClient, private config: AppConfigService) { } - loadKwSearchable(acronym: string) { + /** + * Retrieves searchable keywords for the given acronym. + * + * @param {string} acronym - The acronym. + * + * @return Observable<SvomKeyword[]> + */ + loadKwSearchable(acronym: string): Observable<SvomKeyword[]> { return this.http.get<{search_kw: SvomKeyword[]}[]>(`${this.config.apiUrl}/search/sp_cards?a=8&c=1::eq::${acronym}`).pipe( map(data => data[0].search_kw) ); diff --git a/client/src/app/metamodel/metamodel.module.ts b/client/src/app/metamodel/metamodel.module.ts index 9713c0a547f397d0373c60bb134397685f12ad33..a5d06d880ee034d114796b043240cfe3597db362 100644 --- a/client/src/app/metamodel/metamodel.module.ts +++ b/client/src/app/metamodel/metamodel.module.ts @@ -17,6 +17,10 @@ import { metamodelReducer } from './metamodel.reducer'; import { metamodelEffects } from './effects'; import { metamodelServices} from './services'; +/** + * @class + * @classdesc Metamodel module. + */ @NgModule({ imports: [ CommonModule, diff --git a/client/src/app/metamodel/metamodel.reducer.ts b/client/src/app/metamodel/metamodel.reducer.ts index 6df176d13fce0b8849defbc9de0d4cb327036f93..d7da50592c6ce08bd76d511891f220b6c8c38182 100644 --- a/client/src/app/metamodel/metamodel.reducer.ts +++ b/client/src/app/metamodel/metamodel.reducer.ts @@ -27,6 +27,11 @@ import * as select from './reducers/select.reducer'; import * as selectOption from './reducers/select-option.reducer'; import * as attributeDistinct from './reducers/attribute-distinct.reducer'; +/** + * Interface for metamodel state. + * + * @interface State + */ export interface State { database: database.State; table: table.State; @@ -68,4 +73,3 @@ const reducers = { export const metamodelReducer = combineReducers(reducers); export const getMetamodelState = createFeatureSelector<State>('metamodel'); export const selectRouterState = createFeatureSelector<RouterReducerState>('router'); - \ No newline at end of file diff --git a/client/src/app/metamodel/services/output-category.service.spec.ts b/client/src/app/metamodel/services/output-category.service.spec.ts new file mode 100644 index 0000000000000000000000000000000000000000..3e20ec1ad3631869f4ac51f47111bf6d53464e14 --- /dev/null +++ b/client/src/app/metamodel/services/output-category.service.spec.ts @@ -0,0 +1,102 @@ +import { TestBed, inject } from '@angular/core/testing'; +import { HttpClientTestingModule, HttpTestingController } from '@angular/common/http/testing'; + +import { OutputCategoryService } from './output-category.service'; +import { AppConfigService } from 'src/app/app-config.service'; +import { OutputCategory, OutputFamily } from '../models'; +import { CATEGORY, OUTPUT_FAMILY } from '../../../test-data'; + +describe('[Instance][Metamodel][Services] OutputCategoryService', () => { + let service: OutputCategoryService; + + beforeEach(() => { + TestBed.configureTestingModule({ + imports: [HttpClientTestingModule], + providers: [ + { provide: AppConfigService, useValue: { apiUrl: 'http://testing.com' } }, + OutputCategoryService + ] + }); + service = TestBed.inject(OutputCategoryService); + }); + + it('#retrieveOutputCategoryList() should return an Observable<OutputCategory[]>', + inject([HttpTestingController, OutputCategoryService],(httpMock: HttpTestingController, service: OutputCategoryService) => { + const mockResponse = []; + + service.retrieveOutputCategoryList('myDataset').subscribe((event: OutputCategory[]) => { + expect(event).toEqual(mockResponse); + }); + + const mockRequest = httpMock.expectOne('http://testing.com/dataset/myDataset/output-category'); + + expect(mockRequest.cancelled).toBeFalsy(); + expect(mockRequest.request.method).toEqual('GET'); + expect(mockRequest.request.responseType).toEqual('json'); + mockRequest.flush(mockResponse); + + httpMock.verify(); + } + ) + ); + + it('#addOutputCategory() should return an Observable<OutputCategory>', + inject([HttpTestingController, OutputCategoryService],(httpMock: HttpTestingController, service: OutputCategoryService) => { + const mockResponse = CATEGORY; + + service.addOutputCategory(CATEGORY).subscribe((event: OutputCategory) => { + expect(event).toEqual(mockResponse); + }); + + const mockRequest = httpMock.expectOne('http://testing.com/output-family/1/output-category'); + + expect(mockRequest.cancelled).toBeFalsy(); + expect(mockRequest.request.method).toEqual('POST'); + expect(mockRequest.request.responseType).toEqual('json'); + mockRequest.flush(mockResponse); + + httpMock.verify(); + } + ) + ); + + it('#editOutputCategory() should return an Observable<OutputCategory>', + inject([HttpTestingController, OutputCategoryService],(httpMock: HttpTestingController, service: OutputCategoryService) => { + const mockResponse = CATEGORY; + + service.editOutputCategory(CATEGORY).subscribe((event: OutputCategory) => { + expect(event).toEqual(mockResponse); + }); + + const mockRequest = httpMock.expectOne('http://testing.com/output-category/1'); + + expect(mockRequest.cancelled).toBeFalsy(); + expect(mockRequest.request.method).toEqual('PUT'); + expect(mockRequest.request.responseType).toEqual('json'); + mockRequest.flush(mockResponse); + + httpMock.verify(); + } + ) + ); + + it('#deleteOutputCategory() should return an Observable<object>', + inject([HttpTestingController, OutputCategoryService],(httpMock: HttpTestingController, service: OutputCategoryService) => { + const mockResponse = {}; + + service.deleteOutputCategory(1).subscribe((event: object) => { + expect(event).toEqual(mockResponse); + }); + + const mockRequest = httpMock.expectOne('http://testing.com/output-category/1'); + + expect(mockRequest.cancelled).toBeFalsy(); + expect(mockRequest.request.method).toEqual('DELETE'); + expect(mockRequest.request.responseType).toEqual('json'); + mockRequest.flush(mockResponse); + + httpMock.verify(); + } + ) + ); +}); diff --git a/client/src/app/metamodel/services/output-category.service.ts b/client/src/app/metamodel/services/output-category.service.ts index b13ef00fdb66caecacd3a7d25c428dd263164227..ae9cc7bdff1e1daad2dcda8ff2bedc84591398e3 100644 --- a/client/src/app/metamodel/services/output-category.service.ts +++ b/client/src/app/metamodel/services/output-category.service.ts @@ -15,23 +15,55 @@ import { Observable } from 'rxjs'; import { OutputCategory } from '../models'; import { AppConfigService } from 'src/app/app-config.service'; +/** + * @class + * @classdesc Output category service. + */ @Injectable() export class OutputCategoryService { constructor(private http: HttpClient, private config: AppConfigService) { } + /** + * Retrieves output category list for the given dataset. + * + * @param {string} datasetName - The dataset name. + * + * @return Observable<OutputCategory[]> + */ retrieveOutputCategoryList(datasetName: string): Observable<OutputCategory[]> { return this.http.get<OutputCategory[]>(`${this.config.apiUrl}/dataset/${datasetName}/output-category`); } + /** + * Adds a new output category. + * + * @param {OutputCategory} newOutputCategory - The output category. + * + * @return Observable<OutputCategory> + */ addOutputCategory(newOutputCategory: OutputCategory): Observable<OutputCategory> { return this.http.post<OutputCategory>(`${this.config.apiUrl}/output-family/${newOutputCategory.id_output_family}/output-category`, newOutputCategory); } + /** + * Modifies an output category. + * + * @param {OutputCategory} outputCategory - The output category. + * + * @return Observable<OutputCategory> + */ editOutputCategory(outputCategory: OutputCategory): Observable<OutputCategory> { return this.http.put<OutputCategory>(`${this.config.apiUrl}/output-category/${outputCategory.id}`, outputCategory); } - deleteOutputCategory(outputCategoryId: number) { + /** + * Removes an output category. + * + * @param {number} outputCategoryId - The output category ID. + * + * @return Observable<object> + */ + deleteOutputCategory(outputCategoryId: number): Observable<object> { return this.http.delete(`${this.config.apiUrl}/output-category/${outputCategoryId}`); } } diff --git a/client/src/app/metamodel/services/output-family.service.spec.ts b/client/src/app/metamodel/services/output-family.service.spec.ts new file mode 100644 index 0000000000000000000000000000000000000000..9455a0a8f5ff10aaba49b44ba76fcc6edbe8d741 --- /dev/null +++ b/client/src/app/metamodel/services/output-family.service.spec.ts @@ -0,0 +1,102 @@ +import { TestBed, inject } from '@angular/core/testing'; +import { HttpClientTestingModule, HttpTestingController } from '@angular/common/http/testing'; + +import { OutputFamilyService } from './output-family.service'; +import { AppConfigService } from 'src/app/app-config.service'; +import { OutputFamily } from '../models'; +import { OUTPUT_FAMILY } from '../../../test-data'; + +describe('[Instance][Metamodel][Services] OutputFamilyService', () => { + let service: OutputFamilyService; + + beforeEach(() => { + TestBed.configureTestingModule({ + imports: [HttpClientTestingModule], + providers: [ + { provide: AppConfigService, useValue: { apiUrl: 'http://testing.com' } }, + OutputFamilyService + ] + }); + service = TestBed.inject(OutputFamilyService); + }); + + it('#retrieveOutputFamilyList() should return an Observable<OutputFamily[]>', + inject([HttpTestingController, OutputFamilyService],(httpMock: HttpTestingController, service: OutputFamilyService) => { + const mockResponse = []; + + service.retrieveOutputFamilyList('myDataset').subscribe((event: OutputFamily[]) => { + expect(event).toEqual(mockResponse); + }); + + const mockRequest = httpMock.expectOne('http://testing.com/dataset/myDataset/output-family'); + + expect(mockRequest.cancelled).toBeFalsy(); + expect(mockRequest.request.method).toEqual('GET'); + expect(mockRequest.request.responseType).toEqual('json'); + mockRequest.flush(mockResponse); + + httpMock.verify(); + } + ) + ); + + it('#addOutputFamily() should return an Observable<OutputFamily>', + inject([HttpTestingController, OutputFamilyService],(httpMock: HttpTestingController, service: OutputFamilyService) => { + const mockResponse = OUTPUT_FAMILY; + + service.addOutputFamily('myDataset', OUTPUT_FAMILY).subscribe((event: OutputFamily) => { + expect(event).toEqual(mockResponse); + }); + + const mockRequest = httpMock.expectOne('http://testing.com/dataset/myDataset/output-family'); + + expect(mockRequest.cancelled).toBeFalsy(); + expect(mockRequest.request.method).toEqual('POST'); + expect(mockRequest.request.responseType).toEqual('json'); + mockRequest.flush(mockResponse); + + httpMock.verify(); + } + ) + ); + + it('#editOutputFamily() should return an Observable<OutputFamily>', + inject([HttpTestingController, OutputFamilyService],(httpMock: HttpTestingController, service: OutputFamilyService) => { + const mockResponse = OUTPUT_FAMILY; + + service.editOutputFamily(OUTPUT_FAMILY).subscribe((event: OutputFamily) => { + expect(event).toEqual(mockResponse); + }); + + const mockRequest = httpMock.expectOne('http://testing.com/output-family/1'); + + expect(mockRequest.cancelled).toBeFalsy(); + expect(mockRequest.request.method).toEqual('PUT'); + expect(mockRequest.request.responseType).toEqual('json'); + mockRequest.flush(mockResponse); + + httpMock.verify(); + } + ) + ); + + it('#deleteOutputFamily() should return an Observable<object>', + inject([HttpTestingController, OutputFamilyService],(httpMock: HttpTestingController, service: OutputFamilyService) => { + const mockResponse = {}; + + service.deleteOutputFamily(1).subscribe((event: object) => { + expect(event).toEqual(mockResponse); + }); + + const mockRequest = httpMock.expectOne('http://testing.com/output-family/1'); + + expect(mockRequest.cancelled).toBeFalsy(); + expect(mockRequest.request.method).toEqual('DELETE'); + expect(mockRequest.request.responseType).toEqual('json'); + mockRequest.flush(mockResponse); + + httpMock.verify(); + } + ) + ); +}); diff --git a/client/src/app/metamodel/services/output-family.service.ts b/client/src/app/metamodel/services/output-family.service.ts index 5c73604aa1b9706f3beb798620ef69a2c95c73c8..58c05651adb19e619a8ab041a4c782677f4b1879 100644 --- a/client/src/app/metamodel/services/output-family.service.ts +++ b/client/src/app/metamodel/services/output-family.service.ts @@ -15,23 +15,56 @@ import { Observable } from 'rxjs'; import { OutputFamily } from '../models'; import { AppConfigService } from 'src/app/app-config.service'; +/** + * @class + * @classdesc Output family service. + */ @Injectable() export class OutputFamilyService { constructor(private http: HttpClient, private config: AppConfigService) { } + /** + * Retrieves output family list for the given dataset. + * + * @param {string} datasetName - The dataset name. + * + * @return Observable<OutputFamily[]> + */ retrieveOutputFamilyList(datasetName: string): Observable<OutputFamily[]> { return this.http.get<OutputFamily[]>(`${this.config.apiUrl}/dataset/${datasetName}/output-family`); } + /** + * Adds a new output family for the given dataset. + * + * @param {string} datasetName - The dataset name. + * @param {OutputFamily} newOutputFamily - The output family. + * + * @return Observable<OutputFamily> + */ addOutputFamily(datasetName: string, newOutputFamily: OutputFamily): Observable<OutputFamily> { return this.http.post<OutputFamily>(`${this.config.apiUrl}/dataset/${datasetName}/output-family`, newOutputFamily); } - editOutputFamily(criteriaFamily: OutputFamily): Observable<OutputFamily> { - return this.http.put<OutputFamily>(`${this.config.apiUrl}/output-family/${criteriaFamily.id}`, criteriaFamily); + /** + * Modifies an output family. + * + * @param {OutputFamily} outputFamily - The output family. + * + * @return Observable<OutputFamily> + */ + editOutputFamily(outputFamily: OutputFamily): Observable<OutputFamily> { + return this.http.put<OutputFamily>(`${this.config.apiUrl}/output-family/${outputFamily.id}`, outputFamily); } - deleteOutputFamily(outputFamilyId: number) { + /** + * Removes an output family. + * + * @param {number} outputFamilyId - The output family ID. + * + * @return Observable<object> + */ + deleteOutputFamily(outputFamilyId: number): Observable<object> { return this.http.delete(`${this.config.apiUrl}/output-family/${outputFamilyId}`); } } diff --git a/client/src/app/metamodel/services/root-directory.service.spec.ts b/client/src/app/metamodel/services/root-directory.service.spec.ts new file mode 100644 index 0000000000000000000000000000000000000000..adf40e820e48fd7c0217d4c03afece1a9df2048a --- /dev/null +++ b/client/src/app/metamodel/services/root-directory.service.spec.ts @@ -0,0 +1,41 @@ +import { TestBed, inject } from '@angular/core/testing'; +import { HttpClientTestingModule, HttpTestingController } from '@angular/common/http/testing'; + +import { RootDirectoryService } from './root-directory.service'; +import { AppConfigService } from 'src/app/app-config.service'; +import { FileInfo } from '../models'; + +describe('[Instance][Metamodel][Services] RootDirectoryService', () => { + let service: RootDirectoryService; + + beforeEach(() => { + TestBed.configureTestingModule({ + imports: [HttpClientTestingModule], + providers: [ + { provide: AppConfigService, useValue: { apiUrl: 'http://testing.com' } }, + RootDirectoryService + ] + }); + service = TestBed.inject(RootDirectoryService); + }); + + it('#retrieveRootDirectory() should return an Observable<FileInfo[]>', + inject([HttpTestingController, RootDirectoryService],(httpMock: HttpTestingController, service: RootDirectoryService) => { + const mockResponse = []; + + service.retrieveRootDirectory('/path').subscribe((event: FileInfo[]) => { + expect(event).toEqual(mockResponse); + }); + + const mockRequest = httpMock.expectOne('http://testing.com/file-explorer/path'); + + expect(mockRequest.cancelled).toBeFalsy(); + expect(mockRequest.request.method).toEqual('GET'); + expect(mockRequest.request.responseType).toEqual('json'); + mockRequest.flush(mockResponse); + + httpMock.verify(); + } + ) + ); +}); diff --git a/client/src/app/metamodel/services/root-directory.service.ts b/client/src/app/metamodel/services/root-directory.service.ts index 7935a76d4e87f55e97e5400f86e067b86dc81b47..ed8c19c37fe555106b5d84b8e0ea5041026b2056 100644 --- a/client/src/app/metamodel/services/root-directory.service.ts +++ b/client/src/app/metamodel/services/root-directory.service.ts @@ -15,10 +15,21 @@ import { Observable } from 'rxjs'; import { FileInfo } from '../models'; import { AppConfigService } from 'src/app/app-config.service'; +/** + * @class + * @classdesc Root directory service. + */ @Injectable() export class RootDirectoryService { constructor(private http: HttpClient, private config: AppConfigService) { } + /** + * Retrieves root directory with the given path. + * + * @param {string} path - The path. + * + * @return Observable<FileInfo[]> + */ retrieveRootDirectory(path: string): Observable<FileInfo[]> { return this.http.get<FileInfo[]>(`${this.config.apiUrl}/file-explorer${path}`); } diff --git a/client/src/app/metamodel/services/select-option.service.spec.ts b/client/src/app/metamodel/services/select-option.service.spec.ts new file mode 100644 index 0000000000000000000000000000000000000000..e079e3b0583462fb612e2917cca884937bd8df07 --- /dev/null +++ b/client/src/app/metamodel/services/select-option.service.spec.ts @@ -0,0 +1,102 @@ +import { TestBed, inject } from '@angular/core/testing'; +import { HttpClientTestingModule, HttpTestingController } from '@angular/common/http/testing'; + +import { SelectOptionService } from './select-option.service'; +import { AppConfigService } from 'src/app/app-config.service'; +import { SelectOption } from '../models'; +import { SELECT_OPTION } from '../../../test-data'; + +describe('[Instance][Metamodel][Services] SelectOptionService', () => { + let service: SelectOptionService; + + beforeEach(() => { + TestBed.configureTestingModule({ + imports: [HttpClientTestingModule], + providers: [ + { provide: AppConfigService, useValue: { apiUrl: 'http://testing.com' } }, + SelectOptionService + ] + }); + service = TestBed.inject(SelectOptionService); + }); + + it('#retrieveSelectOptionList() should return an Observable<SelectOption[]>', + inject([HttpTestingController, SelectOptionService],(httpMock: HttpTestingController, service: SelectOptionService) => { + const mockResponse = []; + + service.retrieveSelectOptionList().subscribe((event: SelectOption[]) => { + expect(event).toEqual(mockResponse); + }); + + const mockRequest = httpMock.expectOne('http://testing.com/option'); + + expect(mockRequest.cancelled).toBeFalsy(); + expect(mockRequest.request.method).toEqual('GET'); + expect(mockRequest.request.responseType).toEqual('json'); + mockRequest.flush(mockResponse); + + httpMock.verify(); + } + ) + ); + + it('#addSelectOption() should return an Observable<SelectOption>', + inject([HttpTestingController, SelectOptionService],(httpMock: HttpTestingController, service: SelectOptionService) => { + const mockResponse = SELECT_OPTION; + + service.addSelectOption(SELECT_OPTION).subscribe((event: SelectOption) => { + expect(event).toEqual(mockResponse); + }); + + const mockRequest = httpMock.expectOne('http://testing.com/option'); + + expect(mockRequest.cancelled).toBeFalsy(); + expect(mockRequest.request.method).toEqual('POST'); + expect(mockRequest.request.responseType).toEqual('json'); + mockRequest.flush(mockResponse); + + httpMock.verify(); + } + ) + ); + + it('#editSelectOption() should return an Observable<SelectOption>', + inject([HttpTestingController, SelectOptionService],(httpMock: HttpTestingController, service: SelectOptionService) => { + const mockResponse = SELECT_OPTION; + + service.editSelectOption(SELECT_OPTION).subscribe((event: SelectOption) => { + expect(event).toEqual(mockResponse); + }); + + const mockRequest = httpMock.expectOne('http://testing.com/option/1'); + + expect(mockRequest.cancelled).toBeFalsy(); + expect(mockRequest.request.method).toEqual('PUT'); + expect(mockRequest.request.responseType).toEqual('json'); + mockRequest.flush(mockResponse); + + httpMock.verify(); + } + ) + ); + + it('#deleteSelectOption() should return an Observable<object>', + inject([HttpTestingController, SelectOptionService],(httpMock: HttpTestingController, service: SelectOptionService) => { + const mockResponse = {}; + + service.deleteSelectOption(1).subscribe((event: object) => { + expect(event).toEqual(mockResponse); + }); + + const mockRequest = httpMock.expectOne('http://testing.com/option/1'); + + expect(mockRequest.cancelled).toBeFalsy(); + expect(mockRequest.request.method).toEqual('DELETE'); + expect(mockRequest.request.responseType).toEqual('json'); + mockRequest.flush(mockResponse); + + httpMock.verify(); + } + ) + ); +}); diff --git a/client/src/app/metamodel/services/select-option.service.ts b/client/src/app/metamodel/services/select-option.service.ts index 719b902128db274dd66729fd83e8efeaa52238fb..904a627fff4c326583cb1aa7cc3356ec211999a0 100644 --- a/client/src/app/metamodel/services/select-option.service.ts +++ b/client/src/app/metamodel/services/select-option.service.ts @@ -15,23 +15,51 @@ import { Observable } from 'rxjs'; import { SelectOption } from '../models'; import { AppConfigService } from 'src/app/app-config.service'; +/** + * @class + * @classdesc Select option service. + */ @Injectable() export class SelectOptionService { constructor(private http: HttpClient, private config: AppConfigService) { } + /** + * Retrieves select option list. + * + * @return Observable<SelectOption[]> + */ retrieveSelectOptionList(): Observable<SelectOption[]> { return this.http.get<SelectOption[]>(`${this.config.apiUrl}/option`); } + /** + * Adds a new select option. + * + * @param {SelectOption} settingsSelectOption - The select option. + * + * @return Observable<SelectOption> + */ addSelectOption(settingsSelectOption: SelectOption): Observable<SelectOption> { return this.http.post<SelectOption>(`${this.config.apiUrl}/option`, settingsSelectOption); } + /** + * Modifies a new select option. + * + * @param {SelectOption} settingsSelectOption - The select option. + * + * @return Observable<SelectOption> + */ editSelectOption(settingsSelectOption: SelectOption): Observable<SelectOption> { return this.http.put<SelectOption>(`${this.config.apiUrl}/option/${settingsSelectOption.id}`, settingsSelectOption); } - deleteSelectOption(id: number) { + /** + * Removes a select option. + * + * @param {number} id - The select option ID. + */ + deleteSelectOption(id: number): Observable<object> { return this.http.delete(`${this.config.apiUrl}/option/${id}`); } } diff --git a/client/src/app/metamodel/services/select.service.spec.ts b/client/src/app/metamodel/services/select.service.spec.ts new file mode 100644 index 0000000000000000000000000000000000000000..ab449586c7eae1da626aedcd58503db57c4997b5 --- /dev/null +++ b/client/src/app/metamodel/services/select.service.spec.ts @@ -0,0 +1,102 @@ +import { TestBed, inject } from '@angular/core/testing'; +import { HttpClientTestingModule, HttpTestingController } from '@angular/common/http/testing'; + +import { SelectService } from './select.service'; +import { AppConfigService } from 'src/app/app-config.service'; +import { Select } from '../models'; +import { SELECT } from '../../../test-data'; + +describe('[Instance][Metamodel][Services] SelectService', () => { + let service: SelectService; + + beforeEach(() => { + TestBed.configureTestingModule({ + imports: [HttpClientTestingModule], + providers: [ + { provide: AppConfigService, useValue: { apiUrl: 'http://testing.com' } }, + SelectService + ] + }); + service = TestBed.inject(SelectService); + }); + + it('#retrieveSelectList() should return an Observable<Select[]>', + inject([HttpTestingController, SelectService],(httpMock: HttpTestingController, service: SelectService) => { + const mockResponse = []; + + service.retrieveSelectList().subscribe((event: Select[]) => { + expect(event).toEqual(mockResponse); + }); + + const mockRequest = httpMock.expectOne('http://testing.com/select'); + + expect(mockRequest.cancelled).toBeFalsy(); + expect(mockRequest.request.method).toEqual('GET'); + expect(mockRequest.request.responseType).toEqual('json'); + mockRequest.flush(mockResponse); + + httpMock.verify(); + } + ) + ); + + it('#addSelect() should return an Observable<Select>', + inject([HttpTestingController, SelectService],(httpMock: HttpTestingController, service: SelectService) => { + const mockResponse = SELECT; + + service.addSelect(SELECT).subscribe((event: Select) => { + expect(event).toEqual(mockResponse); + }); + + const mockRequest = httpMock.expectOne('http://testing.com/select'); + + expect(mockRequest.cancelled).toBeFalsy(); + expect(mockRequest.request.method).toEqual('POST'); + expect(mockRequest.request.responseType).toEqual('json'); + mockRequest.flush(mockResponse); + + httpMock.verify(); + } + ) + ); + + it('#editSelect() should return an Observable<Select>', + inject([HttpTestingController, SelectService],(httpMock: HttpTestingController, service: SelectService) => { + const mockResponse = SELECT; + + service.editSelect(SELECT).subscribe((event: Select) => { + expect(event).toEqual(mockResponse); + }); + + const mockRequest = httpMock.expectOne('http://testing.com/select/mySelect'); + + expect(mockRequest.cancelled).toBeFalsy(); + expect(mockRequest.request.method).toEqual('PUT'); + expect(mockRequest.request.responseType).toEqual('json'); + mockRequest.flush(mockResponse); + + httpMock.verify(); + } + ) + ); + + it('#deleteSelect() should return an Observable<object>', + inject([HttpTestingController, SelectService],(httpMock: HttpTestingController, service: SelectService) => { + const mockResponse = {}; + + service.deleteSelect('mySelect').subscribe((event: object) => { + expect(event).toEqual(mockResponse); + }); + + const mockRequest = httpMock.expectOne('http://testing.com/select/mySelect'); + + expect(mockRequest.cancelled).toBeFalsy(); + expect(mockRequest.request.method).toEqual('DELETE'); + expect(mockRequest.request.responseType).toEqual('json'); + mockRequest.flush(mockResponse); + + httpMock.verify(); + } + ) + ); +}); diff --git a/client/src/app/metamodel/services/select.service.ts b/client/src/app/metamodel/services/select.service.ts index f1e440f8f6c87cfd6acb41c370b2407d3ecbac4e..337ed1b2bd66f581ed85987f11b373c09cf0a641 100644 --- a/client/src/app/metamodel/services/select.service.ts +++ b/client/src/app/metamodel/services/select.service.ts @@ -15,23 +15,53 @@ import { Observable } from 'rxjs'; import { Select } from '../models'; import { AppConfigService } from 'src/app/app-config.service'; +/** + * @class + * @classdesc Select service. + */ @Injectable() export class SelectService { constructor(private http: HttpClient, private config: AppConfigService) { } + /** + * Retrieves select list. + * + * @return Observable<Select[]> + */ retrieveSelectList(): Observable<Select[]> { return this.http.get<Select[]>(`${this.config.apiUrl}/select`); } + /** + * Adds a new select. + * + * @param {Select} select - The select. + * + * @return Observable<Select> + */ addSelect(select: Select): Observable<Select> { return this.http.post<Select>(`${this.config.apiUrl}/select`, select); } + /** + * Modifies a select. + * + * @param {Select} select - The select. + * + * @return Observable<Select> + */ editSelect(select: Select): Observable<Select> { return this.http.put<Select>(`${this.config.apiUrl}/select/${select.name}`, select); } - deleteSelect(name: string) { + /** + * Removes a select. + * + * @param {string} name - The select name. + * + * @return Observable<object> + */ + deleteSelect(name: string): Observable<object> { return this.http.delete(`${this.config.apiUrl}/select/${name}`); } } diff --git a/client/src/app/metamodel/services/survey.service.spec.ts b/client/src/app/metamodel/services/survey.service.spec.ts new file mode 100644 index 0000000000000000000000000000000000000000..7d2ca630a025d648d883a76b76a7c4cea0307a0d --- /dev/null +++ b/client/src/app/metamodel/services/survey.service.spec.ts @@ -0,0 +1,102 @@ +import { TestBed, inject } from '@angular/core/testing'; +import { HttpClientTestingModule, HttpTestingController } from '@angular/common/http/testing'; + +import { SurveyService } from './survey.service'; +import { AppConfigService } from 'src/app/app-config.service'; +import { Survey } from '../models'; +import { SURVEY } from '../../../test-data'; + +describe('[Instance][Metamodel][Services] SurveyService', () => { + let service: SurveyService; + + beforeEach(() => { + TestBed.configureTestingModule({ + imports: [HttpClientTestingModule], + providers: [ + { provide: AppConfigService, useValue: { apiUrl: 'http://testing.com' } }, + SurveyService + ] + }); + service = TestBed.inject(SurveyService); + }); + + it('#retrieveSurveyList() should return an Observable<Survey[]>', + inject([HttpTestingController, SurveyService],(httpMock: HttpTestingController, service: SurveyService) => { + const mockResponse = []; + + service.retrieveSurveyList().subscribe((event: Survey[]) => { + expect(event).toEqual(mockResponse); + }); + + const mockRequest = httpMock.expectOne('http://testing.com/survey'); + + expect(mockRequest.cancelled).toBeFalsy(); + expect(mockRequest.request.method).toEqual('GET'); + expect(mockRequest.request.responseType).toEqual('json'); + mockRequest.flush(mockResponse); + + httpMock.verify(); + } + ) + ); + + it('#addSurvey() should return an Observable<Survey>', + inject([HttpTestingController, SurveyService],(httpMock: HttpTestingController, service: SurveyService) => { + const mockResponse = SURVEY; + + service.addSurvey(SURVEY).subscribe((event: Survey) => { + expect(event).toEqual(mockResponse); + }); + + const mockRequest = httpMock.expectOne('http://testing.com/survey'); + + expect(mockRequest.cancelled).toBeFalsy(); + expect(mockRequest.request.method).toEqual('POST'); + expect(mockRequest.request.responseType).toEqual('json'); + mockRequest.flush(mockResponse); + + httpMock.verify(); + } + ) + ); + + it('#editSurvey() should return an Observable<Survey>', + inject([HttpTestingController, SurveyService],(httpMock: HttpTestingController, service: SurveyService) => { + const mockResponse = SURVEY; + + service.editSurvey(SURVEY).subscribe((event: Survey) => { + expect(event).toEqual(mockResponse); + }); + + const mockRequest = httpMock.expectOne('http://testing.com/survey/mySurvey'); + + expect(mockRequest.cancelled).toBeFalsy(); + expect(mockRequest.request.method).toEqual('PUT'); + expect(mockRequest.request.responseType).toEqual('json'); + mockRequest.flush(mockResponse); + + httpMock.verify(); + } + ) + ); + + it('#deleteSurvey() should return an Observable<Survey>', + inject([HttpTestingController, SurveyService],(httpMock: HttpTestingController, service: SurveyService) => { + const mockResponse = {}; + + service.deleteSurvey('mySurvey').subscribe((event: object) => { + expect(event).toEqual(mockResponse); + }); + + const mockRequest = httpMock.expectOne('http://testing.com/survey/mySurvey'); + + expect(mockRequest.cancelled).toBeFalsy(); + expect(mockRequest.request.method).toEqual('DELETE'); + expect(mockRequest.request.responseType).toEqual('json'); + mockRequest.flush(mockResponse); + + httpMock.verify(); + } + ) + ); +}); diff --git a/client/src/app/metamodel/services/survey.service.ts b/client/src/app/metamodel/services/survey.service.ts index d4fdd6e3d294f76786a64dd9a3be5e01e6153131..926e6618528e1bca3a9a2242f68a9bbecaf2cc45 100644 --- a/client/src/app/metamodel/services/survey.service.ts +++ b/client/src/app/metamodel/services/survey.service.ts @@ -15,23 +15,53 @@ import { Observable } from 'rxjs'; import { Survey } from '../models'; import { AppConfigService } from 'src/app/app-config.service'; +/** + * @class + * @classdesc Survey service. + */ @Injectable() export class SurveyService { constructor(private http: HttpClient, private config: AppConfigService) { } + /** + * Retrieves survey list. + * + * @return Observable<Survey[]> + */ retrieveSurveyList(): Observable<Survey[]> { return this.http.get<Survey[]>(`${this.config.apiUrl}/survey`); } + /** + * Adds a new survey. + * + * @param {Survey} newSurvey - The survey. + * + * @return Observable<Survey> + */ addSurvey(newSurvey: Survey): Observable<Survey> { return this.http.post<Survey>(`${this.config.apiUrl}/survey`, newSurvey); } + /** + * Modifies a survey. + * + * @param {Survey} survey - The survey. + * + * @return Observable<Survey> + */ editSurvey(survey: Survey): Observable<Survey> { return this.http.put<Survey>(`${this.config.apiUrl}/survey/${survey.name}`, survey); } - deleteSurvey(surveyName: string) { + /** + * Removes a survey. + * + * @param {string} surveyName - The survey name. + * + * @return Observable<object> + */ + deleteSurvey(surveyName: string): Observable<object> { return this.http.delete(`${this.config.apiUrl}/survey/${surveyName}`); } } diff --git a/client/src/app/metamodel/services/table.service.spec.ts b/client/src/app/metamodel/services/table.service.spec.ts new file mode 100644 index 0000000000000000000000000000000000000000..525cf0841d73a6db25c05cb0a7333b6a3bd80848 --- /dev/null +++ b/client/src/app/metamodel/services/table.service.spec.ts @@ -0,0 +1,39 @@ +import { TestBed, inject } from '@angular/core/testing'; +import { HttpClientTestingModule, HttpTestingController } from '@angular/common/http/testing'; + +import { TableService } from './table.service'; +import { AppConfigService } from 'src/app/app-config.service'; + +describe('[Instance][Metamodel][Services] TableService', () => { + let service: TableService; + + beforeEach(() => { + TestBed.configureTestingModule({ + imports: [HttpClientTestingModule], + providers: [ + { provide: AppConfigService, useValue: { apiUrl: 'http://testing.com' } }, + TableService + ] + }); + service = TestBed.inject(TableService); + }); + + it('#retrieveTableList() should return an Observable<string[]>', + inject([HttpTestingController, TableService],(httpMock: HttpTestingController, service: TableService) => { + const mockResponse = ['Table']; + + service.retrieveTableList(1).subscribe((event: string[]) => { + expect(event).toEqual(mockResponse); + }); + + const mockRequest = httpMock.expectOne('http://testing.com/database/1/table'); + + expect(mockRequest.cancelled).toBeFalsy(); + expect(mockRequest.request.responseType).toEqual('json'); + mockRequest.flush(mockResponse); + + httpMock.verify(); + } + ) + ); +}); diff --git a/client/src/app/metamodel/services/table.service.ts b/client/src/app/metamodel/services/table.service.ts index 2d67e4a1860d21975117bcbcdb99f52401925e4a..c9fe534dca73eeaf4872c377d6615a13062c2c9f 100644 --- a/client/src/app/metamodel/services/table.service.ts +++ b/client/src/app/metamodel/services/table.service.ts @@ -14,10 +14,21 @@ import { Observable } from 'rxjs'; import { AppConfigService } from 'src/app/app-config.service'; +/** + * @class + * @classdesc Table service. + */ @Injectable() export class TableService { constructor(private http: HttpClient, private config: AppConfigService) { } + /** + * Retrieves results for the given parameters. + * + * @param {number} idDatabase - The database ID. + * + * @return Observable<string[]> + */ retrieveTableList(idDatabase: number): Observable<string[]> { return this.http.get<string[]>(`${this.config.apiUrl}/database/${idDatabase}/table`); } diff --git a/client/src/test-data.ts b/client/src/test-data.ts index 69575072bb5b538deaf44ebc1f551865421e38e0..eb8d1dffde3f599faec18e0f33d28fd3da771a56 100644 --- a/client/src/test-data.ts +++ b/client/src/test-data.ts @@ -4,7 +4,7 @@ import { DatasetFamily, Instance, OutputCategory, - OutputFamily, SelectOption, + OutputFamily, Select, SelectOption, Survey } from './app/metamodel/models'; @@ -29,6 +29,16 @@ export const SURVEY_LIST: Survey[] = [ } ]; +export const SURVEY: Survey = { + name: 'mySurvey', + label: 'My Survey', + description: 'This is my survey', + link: 'http://my-survey.com', + manager: 'Orelsan', + id_database: 1, + nb_datasets: 2 +}; + export const INSTANCE_LIST: Instance[] = [ { name: 'myOtherInstance', @@ -410,16 +420,35 @@ export const CATEGORY_LIST: OutputCategory[] = [ } ]; +export const CATEGORY: OutputCategory = { + id: 1, + label: 'Another output category', + display: 20, + id_output_family: 1 +}; + export const OUTPUT_FAMILY_LIST: OutputFamily[] = [ { id: 2, label: 'Output family Two', display: 2, opened: true }, { id: 1, label: 'Output family One', display: 1, opened: false } ]; +export const OUTPUT_FAMILY: OutputFamily = { id: 1, label: 'Output family One', display: 1, opened: false }; + +export const SELECT: Select = { name: 'mySelect', label: 'My select' }; + export const SELECT_OPTION_LIST: SelectOption[] = [ { id: 2, label: 'select_option_label_two', value: 'select_option_label_two', display: 2, select_name: 'name_two' }, { id: 1, label: 'select_option_label_one', value: 'select_option_label_one', display: 1, select_name: 'name_one' } ]; +export const SELECT_OPTION: SelectOption = { + id: 1, + label: 'select_option_label_one', + value: 'select_option_label_one', + display: 1, + select_name: 'name_one' +}; + export const OBJECT_DETAIL: any = { label_four: 'spec1d', label_five: 5