Skip to content

Commit

Permalink
Rewrite load generator with personas - addresses #213
Browse files Browse the repository at this point in the history
Introduce creating projects when none was found instead of returning undefined.
  • Loading branch information
resamsel committed Nov 9, 2020
1 parent 31363d2 commit 6e5e658
Show file tree
Hide file tree
Showing 27 changed files with 698 additions and 300 deletions.
35 changes: 30 additions & 5 deletions ui/libs/generator/src/lib/key.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,13 @@
import { Injector } from '@angular/core';
import { AccessToken, Key, PagedList, Project, Scope } from '@dev/translatr-model';
import { AccessTokenService, KeyService, ProjectService } from '@dev/translatr-sdk';
import {
AccessTokenService,
KeyService,
LocaleService,
MessageService,
ProjectService,
UserService
} from '@dev/translatr-sdk';
import { pickRandomly } from '@translatr/utils';
import { Observable, of } from 'rxjs';
import { concatMap, filter, map } from 'rxjs/operators';
Expand Down Expand Up @@ -67,12 +74,21 @@ export const createRandomKeyForProject = (

export const createRandomKey = (
accessTokenService: AccessTokenService,
userService: UserService,
projectService: ProjectService,
localeService: LocaleService,
keyService: KeyService,
messageService: MessageService,
defaultAccessToken: string
): Observable<Key> => {
return selectRandomProjectAccessToken(accessTokenService, projectService).pipe(
filter(({ project }) => project !== undefined),
return selectRandomProjectAccessToken(
accessTokenService,
userService,
projectService,
localeService,
keyService,
messageService
).pipe(
concatMap(({ project, accessToken }) =>
createRandomKeyForProject(keyService, project, accessToken, defaultAccessToken)
)
Expand Down Expand Up @@ -110,12 +126,21 @@ export const selectRandomKeyForProject = (

export const deleteRandomKey = (
accessTokenService: AccessTokenService,
userService: UserService,
projectService: ProjectService,
localeService: LocaleService,
keyService: KeyService,
messageService: MessageService,
defaultAccessToken: string
): Observable<Key> => {
return selectRandomProjectAccessToken(accessTokenService, projectService).pipe(
filter(({ project }) => Boolean(project)),
return selectRandomProjectAccessToken(
accessTokenService,
userService,
projectService,
localeService,
keyService,
messageService
).pipe(
concatMap(({ accessToken, project }) =>
keyService
.find({
Expand Down
38 changes: 33 additions & 5 deletions ui/libs/generator/src/lib/locale.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,12 @@
import { AccessToken, Locale, PagedList, Project, Scope } from '@dev/translatr-model';
import { AccessTokenService, LocaleService, ProjectService } from '@dev/translatr-sdk';
import {
AccessTokenService,
KeyService,
LocaleService,
MessageService,
ProjectService,
UserService
} from '@dev/translatr-sdk';
import { pickRandomly } from '@translatr/utils';
import { Observable, of } from 'rxjs';
import { concatMap, filter, map } from 'rxjs/operators';
Expand Down Expand Up @@ -56,14 +63,26 @@ export const createRandomLocaleForProject = (
)
);

/**
* Always returns a locale
*/
export const createRandomLocale = (
accessTokenService: AccessTokenService,
userService: UserService,
projectService: ProjectService,
localeService: LocaleService,
keyService: KeyService,
messageService: MessageService,
defaultAccessToken: string
): Observable<Locale> => {
return selectRandomProjectAccessToken(accessTokenService, projectService).pipe(
filter(({ project }) => project !== undefined),
return selectRandomProjectAccessToken(
accessTokenService,
userService,
projectService,
localeService,
keyService,
messageService
).pipe(
concatMap(({ accessToken, project }) =>
createRandomLocaleForProject(localeService, project, accessToken, defaultAccessToken)
)
Expand Down Expand Up @@ -141,12 +160,21 @@ export const selectLocaleForProject = (

export const deleteRandomLocale = (
accessTokenService: AccessTokenService,
userService: UserService,
projectService: ProjectService,
localeService: LocaleService,
keyService: KeyService,
messageService: MessageService,
defaultAccessToken: string
): Observable<Locale> => {
return selectRandomProjectAccessToken(accessTokenService, projectService).pipe(
filter(({ project }) => Boolean(project)),
return selectRandomProjectAccessToken(
accessTokenService,
userService,
projectService,
localeService,
keyService,
messageService
).pipe(
concatMap(({ accessToken, project }) =>
localeService
.find({
Expand Down
22 changes: 19 additions & 3 deletions ui/libs/generator/src/lib/message.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,12 @@
import { AccessToken, Key, Locale, Message, PagedList, Project, Scope } from '@dev/translatr-model';
import { AccessTokenService, MessageService, ProjectService } from '@dev/translatr-sdk';
import {
AccessTokenService,
KeyService,
LocaleService,
MessageService,
ProjectService,
UserService
} from '@dev/translatr-sdk';
import { pickRandomly } from '@translatr/utils';
import { Observable } from 'rxjs';
import { concatMap, filter, map } from 'rxjs/operators';
Expand Down Expand Up @@ -66,12 +73,21 @@ export const updateMessage = (

export const deleteRandomMessage = (
accessTokenService: AccessTokenService,
userService: UserService,
projectService: ProjectService,
localeService: LocaleService,
keyService: KeyService,
messageService: MessageService,
defaultAccessToken: string
): Observable<Message> => {
return selectRandomProjectAccessToken(accessTokenService, projectService).pipe(
filter(({ project }) => Boolean(project)),
return selectRandomProjectAccessToken(
accessTokenService,
userService,
projectService,
localeService,
keyService,
messageService
).pipe(
concatMap(({ accessToken, project }) =>
messageService
.find({
Expand Down
19 changes: 15 additions & 4 deletions ui/libs/generator/src/lib/personas/abraham.persona.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,14 @@ import { Injector } from '@angular/core';
import {
AccessTokenService,
errorMessage,
KeyService,
LocaleService,
ProjectService
MessageService,
ProjectService,
UserService
} from '@dev/translatr-sdk';
import { Observable, of } from 'rxjs';
import { catchError, filter, map } from 'rxjs/operators';
import { catchError, map } from 'rxjs/operators';
import { LoadGeneratorConfig } from '../load-generator-config';
import { createRandomLocale } from '../locale';
import { WeightedPersona } from '../weighted-persona';
Expand All @@ -23,26 +26,34 @@ const info: WeightedPersona = {
};

export class AbrahamPersona extends Persona {
private readonly accessTokenService: AccessTokenService;
private readonly userService: UserService;
private readonly projectService: ProjectService;
private readonly localeService: LocaleService;
private readonly accessTokenService: AccessTokenService;
private readonly keyService: KeyService;
private readonly messageService: MessageService;

constructor(config: LoadGeneratorConfig, injector: Injector) {
super(info.name, config, injector);

this.accessTokenService = injector.get(AccessTokenService);
this.userService = injector.get(UserService);
this.projectService = injector.get(ProjectService);
this.localeService = injector.get(LocaleService);
this.keyService = injector.get(KeyService);
this.messageService = injector.get(MessageService);
}

execute(): Observable<string> {
return createRandomLocale(
this.accessTokenService,
this.userService,
this.projectService,
this.localeService,
this.keyService,
this.messageService,
this.config.accessToken
).pipe(
filter(locale => Boolean(locale)),
map(
locale =>
`locale ${locale.name} for project ${locale.projectOwnerUsername}/${locale.projectName} created`
Expand Down
17 changes: 14 additions & 3 deletions ui/libs/generator/src/lib/personas/anna.persona.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,14 @@ import { Injector } from '@angular/core';
import {
AccessTokenService,
errorMessage,
KeyService,
LocaleService,
ProjectService
MessageService,
ProjectService,
UserService
} from '@dev/translatr-sdk';
import { Observable, of } from 'rxjs';
import { catchError, filter, map } from 'rxjs/operators';
import { catchError, map } from 'rxjs/operators';
import { LoadGeneratorConfig } from '../load-generator-config';
import { deleteRandomLocale } from '../locale';
import { WeightedPersona } from '../weighted-persona';
Expand All @@ -24,25 +27,33 @@ const info: WeightedPersona = {

export class AnnaPersona extends Persona {
private readonly accessTokenService: AccessTokenService;
private readonly userService: UserService;
private readonly projectService: ProjectService;
private readonly localeService: LocaleService;
private readonly keyService: KeyService;
private readonly messageService: MessageService;

constructor(config: LoadGeneratorConfig, injector: Injector) {
super(info.name, config, injector);

this.accessTokenService = injector.get(AccessTokenService);
this.userService = injector.get(UserService);
this.projectService = injector.get(ProjectService);
this.localeService = injector.get(LocaleService);
this.keyService = injector.get(KeyService);
this.messageService = injector.get(MessageService);
}

execute(): Observable<string> {
return deleteRandomLocale(
this.accessTokenService,
this.userService,
this.projectService,
this.localeService,
this.keyService,
this.messageService,
this.config.accessToken
).pipe(
filter(locale => Boolean(locale)),
map(
locale =>
`locale ${locale.name} of project ${locale.projectOwnerUsername}/${locale.projectName} removed`
Expand Down
Loading

0 comments on commit 6e5e658

Please sign in to comment.