Skip to content

Commit

Permalink
feat: added support for default locale
Browse files Browse the repository at this point in the history
  • Loading branch information
TheSlimvReal committed Nov 21, 2023
1 parent fd6a693 commit fa9cbef
Show file tree
Hide file tree
Showing 4 changed files with 41 additions and 10 deletions.
11 changes: 11 additions & 0 deletions integrations/elementor-plugin/form-actions/aam-deploy.php
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,7 @@ public function run( $record, $ajax_handler ) {
'client' => $settings['client'],
'clientKey' => $settings['client-key'],
'base' => $settings['base'],
'locale' => $settings['locale'],
]),
'httpversion' => '1.0',
'timeout' => 60,
Expand Down Expand Up @@ -152,6 +153,16 @@ public function register_settings_section( $widget ) {
]
);

$widget->add_control(
'locale',
[
'label' => esc_html__( 'Language', 'elementor-forms-aam-deploy' ),
'type' => \Elementor\Controls_Manager::TEXT,
'description' => esc_html__( 'Enter the default language for the deployed app ("en", "de",...).', 'elementor-forms-aam-deploy' ),
'default' => 'en'
]
);

$widget->add_control(
'base',
[
Expand Down
29 changes: 24 additions & 5 deletions src/app.controller.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,9 @@ import * as fs from 'fs';
describe('AppController', () => {
let controller: AppController;
let mockHttp: { post: jest.Mock };
const delpoymentData: DeploymentInfo = {
const deploymentData: DeploymentInfo = {
name: 'test-name',
locale: 'de',
username: 'test-username',
email: '[email protected]',
client: 'test-client',
Expand Down Expand Up @@ -42,7 +43,7 @@ describe('AppController', () => {
throwError(() => new UnauthorizedException()),
);

controller.deployApp(delpoymentData).subscribe({
controller.deployApp(deploymentData).subscribe({
error: (err) => {
expect(err).toBeInstanceOf(UnauthorizedException);
done();
Expand All @@ -51,7 +52,7 @@ describe('AppController', () => {
});

it('should throw bad request exception if data has wrong format', (done) => {
const invalidData = { ...delpoymentData, name: 'with space' };
const invalidData = { ...deploymentData, name: 'with space' };

controller.deployApp(invalidData).subscribe({
error: (err) => {
Expand All @@ -65,11 +66,29 @@ describe('AppController', () => {
const mockWs = { write: jest.fn(), close: jest.fn() };
jest.spyOn(fs, 'createWriteStream').mockReturnValue(mockWs as any);

await firstValueFrom(controller.deployApp(delpoymentData));
await firstValueFrom(controller.deployApp(deploymentData));

expect(mockWs.write).toHaveBeenCalledWith(
'test-name [email protected] test-username test-base y n',
'test-name de [email protected] test-username test-base y n',
);
expect(mockWs.close).toHaveBeenCalled();
});

it('should use the default locale if empty or omitted', async () => {
const mockWs = { write: jest.fn(), close: jest.fn() };
jest.spyOn(fs, 'createWriteStream').mockReturnValue(mockWs as any);

const withoutLocale = { ...deploymentData, locale: '' };
await firstValueFrom(controller.deployApp(withoutLocale));
expect(mockWs.write).toHaveBeenCalledWith(
'test-name en [email protected] test-username test-base y n',
);

mockWs.write.mockReset();
delete withoutLocale.locale;
await firstValueFrom(controller.deployApp(withoutLocale));
expect(mockWs.write).toHaveBeenCalledWith(
'test-name en [email protected] test-username test-base y n',
);
});
});
10 changes: 5 additions & 5 deletions src/app.controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -50,11 +50,11 @@ export class AppController {
throw new BadRequestException('No spaces allowed in arguments');
}

const args = `${deploymentInfo.name} ${deploymentInfo.email} ${
deploymentInfo.username
} ${deploymentInfo.base} ${deploymentInfo.backend ? 'y' : 'n'} ${
deploymentInfo.monitor ? 'y' : 'n'
}`;
const args = `${deploymentInfo.name} ${deploymentInfo.locale || 'en'} ${
deploymentInfo.email
} ${deploymentInfo.username} ${deploymentInfo.base} ${
deploymentInfo.backend ? 'y' : 'n'
} ${deploymentInfo.monitor ? 'y' : 'n'}`;
console.log('args', args);
const ws = fs.createWriteStream('dist/assets/arg-pipe');
ws.write(args);
Expand Down
1 change: 1 addition & 0 deletions src/deployment-info.dto.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
export class DeploymentInfo {
name: string;
locale?: string;
username: string;
email: string;
backend: boolean;
Expand Down

0 comments on commit fa9cbef

Please sign in to comment.