Skip to content

Commit

Permalink
Migrate to latest Play version - addresses #92
Browse files Browse the repository at this point in the history
- cleans up load generator
- fixes issues discovered by load test
  • Loading branch information
resamsel committed Nov 9, 2020
1 parent 00c0892 commit 5142533
Show file tree
Hide file tree
Showing 5 changed files with 45 additions and 29 deletions.
15 changes: 8 additions & 7 deletions ui/libs/generator/src/lib/key.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,28 +25,29 @@ export const featureNames = [
'dashboard',
'admin'
];
export const parts = ['list', 'detail', 'find', 'search', 'main', 'header', 'footer'];
export const keySuffixes = [
'title',
'header',
'description',
'list',
'text',
'comment',
'get',
'create',
'update',
'delete',
'permission',
'find',
'search',
'sell',
'confirm',
'allow',
'restricted',
'filter',
'clear'
];
export const keyNames = cartesianProduct([featureNames, keySuffixes]).map((values: string[]) =>
values.join('.')
);
export const keyNames = cartesianProduct([
featureNames,
parts,
keySuffixes
]).map((values: string[]) => values.join('.'));

export const createKey = (
injector: Injector,
Expand Down
4 changes: 4 additions & 0 deletions ui/libs/generator/src/lib/locale.ts
Original file line number Diff line number Diff line change
Expand Up @@ -130,6 +130,10 @@ export const deleteRandomLocale = (injector: Injector): Observable<Partial<State
}))
)
),
filter(
(payload: { user: User; accessToken: AccessToken; project: Project; locales: Locale[] }) =>
payload.locales.length > 0
),
concatMap(
(payload: { user: User; accessToken: AccessToken; project: Project; locales: Locale[] }) =>
deleteLocale(
Expand Down
46 changes: 26 additions & 20 deletions ui/libs/generator/src/lib/project/project.ts
Original file line number Diff line number Diff line change
Expand Up @@ -66,30 +66,32 @@ export const createRandomProject = (injector: Injector): Observable<Partial<Stat
),
concatMap((payload: { user: User; project: Project; accessToken: AccessToken }) => {
return combineLatest(
_.sample(localeNames, Math.ceil(Math.random() * 12)).map((localeName: string) =>
createLocale(
injector,
{
name: localeName,
projectId: payload.project.id
},
payload.accessToken
)
)
).pipe(map((locales: Locale[]) => ({ ...payload, locales })));
}),
concatMap(
(payload: { user: User; project: Project; locales: Locale[]; accessToken: AccessToken }) => {
return combineLatest(
_.sample(keyNames, Math.ceil(Math.random() * 50)).map((keyName: string) =>
createKey(
_.sample(localeNames, Math.ceil(Math.random() * localeNames.length)).map(
(localeName: string) =>
createLocale(
injector,
{
name: keyName,
name: localeName,
projectId: payload.project.id
},
payload.accessToken
)
)
).pipe(map((locales: Locale[]) => ({ ...payload, locales })));
}),
concatMap(
(payload: { user: User; project: Project; locales: Locale[]; accessToken: AccessToken }) => {
return combineLatest(
_.sample(keyNames, Math.ceil((Math.random() * keyNames.length) / 10)).map(
(keyName: string) =>
createKey(
injector,
{
name: keyName,
projectId: payload.project.id
},
payload.accessToken
)
)
).pipe(map((keys: Key[]) => ({ ...payload, keys })));
}
Expand Down Expand Up @@ -122,7 +124,9 @@ export const createRandomProject = (injector: Injector): Observable<Partial<Stat
message: `${payload.user.name} created project ${payload.project.name} with \
${payload.locales.length} languages and ${payload.keys.length} keys`
})),
catchError((err: HttpErrorResponse) => of({ message: errorMessage(err) }))
catchError((err: HttpErrorResponse) =>
of({ message: `createRandomProject: ${errorMessage(err)}` })
)
);
};

Expand Down Expand Up @@ -176,7 +180,9 @@ export const updateRandomProject = (injector: Injector): Observable<Partial<Stat
map((payload: { user: User; project: Project }) => ({
message: `${payload.user.name} updated project ${payload.project.name}`
})),
catchError((err: HttpErrorResponse) => of({ message: errorMessage(err) }))
catchError((err: HttpErrorResponse) =>
of({ message: `updateRandomProject: ${errorMessage(err)}` })
)
);
};

Expand Down
2 changes: 1 addition & 1 deletion ui/libs/generator/src/lib/user.ts
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ export const createRandomUser = (userService: UserService): Observable<Partial<S
const firstName = randomName.first();
const lastName = randomName.last();
const name = `${firstName} ${lastName}`;
const username = name.replace(' ', '').toLowerCase();
const username = name.replace(/[^a-zA-Z0-9]/, '').toLowerCase();
const email = `${firstName}.${lastName}@repanzar.com`;
return userService
.create({
Expand Down
7 changes: 6 additions & 1 deletion ui/libs/translatr-sdk/src/lib/services/error-handler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,12 @@ Error: ${JSON.stringify(error, null, 2)}

export class ErrorHandler {
handleError(error: HttpErrorResponse, request?: RestRequest): Observable<never> {
console.warn(errorTemplate(error, request));
if (
error.error?.error?.violations[0]?.message !== 'error.nameunique' &&
error.error?.error?.violations[0]?.message !== 'Entry already exists (duplicate key)'
) {
console.warn(errorTemplate(error, request));
}
return throwError(error);
}
}

0 comments on commit 5142533

Please sign in to comment.