Merged in HIMA-38 (pull request #9)

HIMA-38
This commit is contained in:
Lorenz Hilpert
2019-02-01 13:25:22 +00:00
committed by Eraldo Hasanaj
26 changed files with 391 additions and 5 deletions

View File

@@ -168,6 +168,41 @@
}
}
}
},
"feed-service": {
"root": "projects/feed-service",
"sourceRoot": "projects/feed-service/src",
"projectType": "library",
"prefix": "lib",
"architect": {
"build": {
"builder": "@angular-devkit/build-ng-packagr:build",
"options": {
"tsConfig": "projects/feed-service/tsconfig.lib.json",
"project": "projects/feed-service/ng-package.json"
}
},
"test": {
"builder": "@angular-devkit/build-angular:karma",
"options": {
"main": "projects/feed-service/src/test.ts",
"tsConfig": "projects/feed-service/tsconfig.spec.json",
"karmaConfig": "projects/feed-service/karma.conf.js"
}
},
"lint": {
"builder": "@angular-devkit/build-angular:tslint",
"options": {
"tsConfig": [
"projects/feed-service/tsconfig.lib.json",
"projects/feed-service/tsconfig.spec.json"
],
"exclude": [
"**/node_modules/**"
]
}
}
}
}
},
"defaultProject": "hima"

View File

@@ -14,6 +14,7 @@ pipelines:
- umask 0022
- npm install
- node_modules/.bin/ng build cat-service
- node_modules/.bin/ng build feed-service
- node_modules/.bin/ng build --prod
- tar cfz /tmp/$BITBUCKET_BRANCH-$BITBUCKET_REPO_SLUG.tgz -C dist/hima/ .
- scp /tmp/$BITBUCKET_BRANCH-$BITBUCKET_REPO_SLUG.tgz $DEPLOYMENT_USER@$TESTING_HOST:/tmp/
@@ -26,6 +27,7 @@ pipelines:
- umask 0022
- npm install
- node_modules/.bin/ng build cat-service
- node_modules/.bin/ng build feed-service
- node_modules/.bin/ng build
- tar cfz /tmp/$BITBUCKET_BRANCH-$BITBUCKET_REPO_SLUG.tgz -C dist/hima/ .
- scp /tmp/$BITBUCKET_BRANCH-$BITBUCKET_REPO_SLUG.tgz $DEPLOYMENT_USER@$TESTING_HOST:/tmp/

10
package-lock.json generated
View File

@@ -767,11 +767,21 @@
"resolved": "https://registry.npmjs.org/@ngrx/effects/-/effects-7.1.0.tgz",
"integrity": "sha512-0oF9VaixL8TNzIyBfFieLXunoz66uuceGfh5EaepQu+qPcVhnFq5KvYHDQOdCq0uuQYB7rVwNFYjOD7pO5LE5A=="
},
"@ngrx/router-store": {
"version": "7.2.0",
"resolved": "https://registry.npmjs.org/@ngrx/router-store/-/router-store-7.2.0.tgz",
"integrity": "sha512-deXDZg4FffuqxlFXqAaR8+lEy4yCJgTmKn2avKHltF3GP+8bxIRiD6GDCYjYJVhLFiBK8U3AFhgfoEuUUpFCag=="
},
"@ngrx/store": {
"version": "7.1.0",
"resolved": "https://registry.npmjs.org/@ngrx/store/-/store-7.1.0.tgz",
"integrity": "sha512-tM8ZGxbLTyQ5JUHow3/PSFU3FWfYJs/wAVyRlxzTxfY7Krs/TJ64GgI4lOa6gVizi2UiYfLtI31pJrxzXyxEoA=="
},
"@ngrx/store-devtools": {
"version": "7.2.0",
"resolved": "https://registry.npmjs.org/@ngrx/store-devtools/-/store-devtools-7.2.0.tgz",
"integrity": "sha512-t+8K1IG8+MvFqLIuRSM+ZE1EkZIuUExJ0JsqZR4r4K3MRPRoGy1ZqlStBWYaYLumEToesiCOGxuJYQ4zyVwlZg=="
},
"@ngtools/json-schema": {
"version": "1.1.0",
"resolved": "https://registry.npmjs.org/@ngtools/json-schema/-/json-schema-1.1.0.tgz",

View File

@@ -2,7 +2,7 @@ import { TestBed, getTestBed } from '@angular/core/testing';
import { HttpClientTestingModule, HttpTestingController } from '@angular/common/http/testing';
import { CatSearchService } from './cat-search.service';
import { QueryTokenDTO } from './dtos/query';
import { QueryTokenDTO, AutocompleteTokenDTO } from './dtos/query';
import { CAT_SERVICE_ENDPOINT } from './tokens';
describe('CatSearchService', () => {
@@ -73,7 +73,7 @@ describe('CatSearchService', () => {
}).subscribe();
const req = httpMock.expectOne({ method: 'POST', url: '/ora/complete' });
const body: QueryTokenDTO = req.request.body;
const body: AutocompleteTokenDTO = req.request.body;
expect(body.input).toBe('test');
expect(body.take).toBe(25);
@@ -98,7 +98,20 @@ describe('CatSearchService', () => {
httpMock.expectOne({ method: 'GET', url: '/ora/settings' });
});
it('should return the cached response', () => {
service.settings().subscribe();
httpMock.expectOne({ method: 'GET', url: '/ora/settings' });
service.settings().subscribe();
httpMock.expectNone({ method: 'GET', url: '/ora/settings' })
});
it('should force a second response', () => {
service.settings().subscribe();
httpMock.expectOne({ method: 'GET', url: '/ora/settings' });
service.settings({ force: true }).subscribe();
httpMock.expectOne({ method: 'GET', url: '/ora/settings' });
});
});
});

View File

@@ -1,6 +1,6 @@
import { StringDictionary } from './models/dictionary.model';
export class ApiResponse<T = void> {
export interface ApiResponse<T = void> {
requestId: number;
message: string;
error: boolean;
@@ -8,7 +8,7 @@ export class ApiResponse<T = void> {
result: T;
}
export class PagedApiResponse<T> extends ApiResponse<T[]> {
export interface PagedApiResponse<T> extends ApiResponse<T[]> {
skip: number;
take: number;
hits: number;

View File

@@ -0,0 +1,24 @@
# FeedService
This library was generated with [Angular CLI](https://github.com/angular/angular-cli) version 7.2.0.
## Code scaffolding
Run `ng generate component component-name --project feed-service` to generate a new component. You can also use `ng generate directive|pipe|service|class|guard|interface|enum|module --project feed-service`.
> Note: Don't forget to add `--project feed-service` or else it will be added to the default project in your `angular.json` file.
## Build
Run `ng build feed-service` to build the project. The build artifacts will be stored in the `dist/` directory.
## Publishing
After building your library with `ng build feed-service`, go to the dist folder `cd dist/feed-service` and run `npm publish`.
## Running unit tests
Run `ng test feed-service` to execute the unit tests via [Karma](https://karma-runner.github.io).
## Further help
To get more help on the Angular CLI use `ng help` or go check out the [Angular CLI README](https://github.com/angular/angular-cli/blob/master/README.md).

View File

@@ -0,0 +1,31 @@
// Karma configuration file, see link for more information
// https://karma-runner.github.io/1.0/config/configuration-file.html
module.exports = function (config) {
config.set({
basePath: '',
frameworks: ['jasmine', '@angular-devkit/build-angular'],
plugins: [
require('karma-jasmine'),
require('karma-chrome-launcher'),
require('karma-jasmine-html-reporter'),
require('karma-coverage-istanbul-reporter'),
require('@angular-devkit/build-angular/plugins/karma')
],
client: {
clearContext: false // leave Jasmine Spec Runner output visible in browser
},
coverageIstanbulReporter: {
dir: require('path').join(__dirname, '../../coverage/feed-service'),
reports: ['html', 'lcovonly'],
fixWebpackSourcePaths: true
},
reporters: ['progress', 'kjhtml'],
port: 9876,
colors: true,
logLevel: config.LOG_INFO,
autoWatch: true,
browsers: ['Chrome'],
singleRun: false
});
};

View File

@@ -0,0 +1,7 @@
{
"$schema": "../../node_modules/ng-packagr/ng-package.schema.json",
"dest": "../../dist/feed-service",
"lib": {
"entryFile": "src/public_api.ts"
}
}

View File

@@ -0,0 +1,8 @@
{
"name": "feed-service",
"version": "0.0.1",
"peerDependencies": {
"@angular/common": "^7.2.0",
"@angular/core": "^7.2.0"
}
}

View File

@@ -0,0 +1,10 @@
export interface EventInfoDTO {
id?: number;
name: string;
desc: string;
image: string;
type: string;
start?: Date;
stop?: Date;
venue: string;
}

View File

@@ -0,0 +1,8 @@
export interface FeedDTO<T = void> {
id: string;
type: string;
label: string;
image: string;
desc: string;
items?: T[];
}

View File

@@ -0,0 +1,5 @@
// start:ng42.barrel
export * from './event-info.dto';
export * from './feed.dto';
// end:ng42.barrel

View File

@@ -0,0 +1,10 @@
import { NgModule, ModuleWithProviders } from '@angular/core';
@NgModule()
export class FeedServiceModule {
static forRoot(): ModuleWithProviders {
return {
ngModule: FeedServiceModule
};
}
}

View File

@@ -0,0 +1,51 @@
import { TestBed } from '@angular/core/testing';
import { FeedService } from './feed.service';
import { HttpClientTestingModule, HttpTestingController } from '@angular/common/http/testing';
import { FEED_SERVICE_ENDPOINT } from './tokens';
describe('FeedService', () => {
const endpoint = 'http://test-feed.com';
let service: FeedService;
let httpMock: HttpTestingController;
beforeEach(() => {
TestBed.configureTestingModule({
imports: [HttpClientTestingModule],
providers: [
{ provide: FEED_SERVICE_ENDPOINT, useValue: endpoint },
FeedService
]
});
service = TestBed.get(FeedService);
httpMock = TestBed.get(HttpTestingController);
});
describe('#info', () => {
it('should issue an get /isa/info request ', () => {
service.info().subscribe();
httpMock.expectOne({ method: 'GET', url: `${endpoint}/isa/info` });
});
it('should set skip as query parameter', () => {
service.info({ skip: 12 }).subscribe();
const req = httpMock.expectOne(r => r.method === 'GET' && r.url === `${endpoint}/isa/info`);
expect(req.request.params.get('skip')).toBe('12');
});
it('should set take as query parameter', () => {
service.info({ take: 10 }).subscribe();
const req = httpMock.expectOne(r => r.method === 'GET' && r.url === `${endpoint}/isa/info`);
expect(req.request.params.get('take')).toBe('10');
});
});
});

View File

@@ -0,0 +1,33 @@
import { Injectable, Inject } from '@angular/core';
import { FEED_SERVICE_ENDPOINT } from './tokens';
import { PagedApiResponse } from './response';
import { FeedDTO } from './dtos/feed.dto';
import { Observable } from 'rxjs';
import { HttpClient } from '@angular/common/http';
import { StringDictionary } from './models';
import { isNumber } from 'util';
@Injectable({ providedIn: 'root' })
export class FeedService {
constructor(@Inject(FEED_SERVICE_ENDPOINT) private endpoint: string, private http: HttpClient) { }
info(options?: { skip?: number; take?: number; }): Observable<PagedApiResponse<FeedDTO>> {
const params: StringDictionary<string | string[]> = {};
if (!!options) {
if (isNumber(options.skip)) {
params['skip'] = String(options.skip);
}
if (isNumber(options.take)) {
params['take'] = String(options.take);
}
}
return this.http.get<PagedApiResponse<FeedDTO>>(
`${this.endpoint}/isa/info`,
{ params }
);
}
}

View File

@@ -0,0 +1,9 @@
// start:ng42.barrel
export * from './feed-service.module';
export * from './feed.service';
export * from './response';
export * from './tokens';
export * from './dtos';
export * from './models';
// end:ng42.barrel

View File

@@ -0,0 +1,7 @@
export interface StringDictionary<T> {
[key: string]: T;
}
export interface NumberDictionary<T> {
[key: number]: T;
}

View File

@@ -0,0 +1,4 @@
// start:ng42.barrel
export * from './dictionary.model';
// end:ng42.barrel

View File

@@ -0,0 +1,15 @@
import { StringDictionary } from './models/dictionary.model';
export interface ApiResponse<T = void> {
requestId: number;
message: string;
error: boolean;
invalidProperties: StringDictionary<string>;
result: T;
}
export interface PagedApiResponse<T> extends ApiResponse<T[]> {
skip: number;
take: number;
hits: number;
}

View File

@@ -0,0 +1,3 @@
import { InjectionToken } from '@angular/core';
export const FEED_SERVICE_ENDPOINT = new InjectionToken<string>('feed:service:endpoint');

View File

@@ -0,0 +1,10 @@
/*
* Public API Surface of feed-service
*/
export * from './lib/feed-service.module';
export * from './lib/feed.service';
export * from './lib/response';
export * from './lib/tokens';
export * from './lib/dtos';
export * from './lib/models';

View File

@@ -0,0 +1,22 @@
// This file is required by karma.conf.js and loads recursively all the .spec and framework files
import 'core-js/es7/reflect';
import 'zone.js/dist/zone';
import 'zone.js/dist/zone-testing';
import { getTestBed } from '@angular/core/testing';
import {
BrowserDynamicTestingModule,
platformBrowserDynamicTesting
} from '@angular/platform-browser-dynamic/testing';
declare const require: any;
// First, initialize the Angular testing environment.
getTestBed().initTestEnvironment(
BrowserDynamicTestingModule,
platformBrowserDynamicTesting()
);
// Then we find all the tests.
const context = require.context('./', true, /\.spec\.ts$/);
// And load the modules.
context.keys().map(context);

View File

@@ -0,0 +1,32 @@
{
"extends": "../../tsconfig.json",
"compilerOptions": {
"outDir": "../../out-tsc/lib",
"target": "es2015",
"module": "es2015",
"moduleResolution": "node",
"declaration": true,
"sourceMap": true,
"inlineSources": true,
"emitDecoratorMetadata": true,
"experimentalDecorators": true,
"importHelpers": true,
"types": [],
"lib": [
"dom",
"es2018"
]
},
"angularCompilerOptions": {
"annotateForClosureCompiler": true,
"skipTemplateCodegen": true,
"strictMetadataEmit": true,
"fullTemplateTypeCheck": true,
"strictInjectionParameters": true,
"enableResourceInlining": true
},
"exclude": [
"src/test.ts",
"**/*.spec.ts"
]
}

View File

@@ -0,0 +1,17 @@
{
"extends": "../../tsconfig.json",
"compilerOptions": {
"outDir": "../../out-tsc/spec",
"types": [
"jasmine",
"node"
]
},
"files": [
"src/test.ts"
],
"include": [
"**/*.spec.ts",
"**/*.d.ts"
]
}

View File

@@ -0,0 +1,17 @@
{
"extends": "../../tslint.json",
"rules": {
"directive-selector": [
true,
"attribute",
"lib",
"camelCase"
],
"component-selector": [
true,
"element",
"lib",
"kebab-case"
]
}
}

View File

@@ -21,6 +21,9 @@
"paths": {
"cat-service": [
"dist/cat-service"
],
"feed-service": [
"dist/feed-service"
]
}
}