Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Tests fail if RPS server isn't localhost #808

Open
orinem opened this issue Aug 5, 2022 · 1 comment
Open

Tests fail if RPS server isn't localhost #808

orinem opened this issue Aug 5, 2022 · 1 comment
Labels
good first issue Good for newcomers P3 Priority 3 - Low

Comments

@orinem
Copy link
Contributor

orinem commented Aug 5, 2022

To Reproduce 🪜
Steps to reproduce the behavior:

Change the environment to use a remote RPS server, for example:

diff --git a/src/environments/environment.ts b/src/environments/environment.ts
index 63d436c..7904a38 100644
--- a/src/environments/environment.ts
+++ b/src/environments/environment.ts
@@ -9,9 +9,9 @@
 
 export const environment = {
   production: false,
-  mpsServer: 'http://localhost:3000',
-  rpsServer: 'http://localhost:8081',
-  vault: 'http://localhost/vault'
+  mpsServer: 'https://10.0.0.219/mps',
+  rpsServer: 'https://10.0.0.219/rps',
+  vault: 'https://10.0.0.219/vault'
 }
 
 /*

The tests will fail as they have 'localhost' hardcoded in some strings.

Expected behavior

Tests should succeed.

Additional context

This will fix the problem. Using 'URL' to extract the hostname should be different enough to component.formServerUrl() for the test to be worthwhile.

diff --git a/src/app/shared/deactivate-device/deactivate-device.component.spec.ts b/src/app/shared/deactivate-device/deactivate-device.component.spec.ts
index babe200..cbd8909 100644
--- a/src/app/shared/deactivate-device/deactivate-device.component.spec.ts
+++ b/src/app/shared/deactivate-device/deactivate-device.component.spec.ts
@@ -51,7 +51,7 @@ describe('DeactivateDeviceComponent', () => {
     expect(component.rpcLinux).toBe('sudo ./rpc ')
     expect(component.rpcDocker).toBe('sudo docker run --device=/dev/mei0 rpc:latest ')
     expect(component.rpcWindows).toBe('rpc.exe ')
-    expect(component.deactivationUrl).toBe('sudo ./rpc -u wss://localhost/activate ')
+    expect(component.deactivationUrl).toBe('sudo ./rpc -u wss://' + new URL(environment.rpsServer).hostname + '/activate ')
     expect(component.serverUrl).toBe(`-u wss://${component.formServerUrl()}/activate `)
     expect(component.deactivationCommand).toBe('')
     expect(component.isCopied).toBe(false)
@@ -75,17 +75,17 @@ describe('DeactivateDeviceComponent', () => {
   it('should set linux deactivation url', () => {
     component.selectedPlatform = 'Linux'
     component.formDeactivationUrl()
-    expect(component.deactivationUrl).toBe('sudo ./rpc -u wss://localhost/activate ')
+    expect(component.deactivationUrl).toBe('sudo ./rpc -u wss://' + new URL(environment.rpsServer).hostname + '/activate ')
   })
   it('should set windows deactivation url', () => {
     component.selectedPlatform = 'wiNDows'
     component.formDeactivationUrl()
-    expect(component.deactivationUrl).toBe('rpc.exe -u wss://localhost/activate ')
+    expect(component.deactivationUrl).toBe('rpc.exe -u wss://' + new URL(environment.rpsServer).hostname + '/activate ')
   })
   it('should set docker deactivation url', () => {
     component.selectedPlatform = 'docker'
     component.formDeactivationUrl()
-    expect(component.deactivationUrl).toBe('sudo docker run --device=/dev/mei0 rpc:latest -u wss://localhost/activate ')
+    expect(component.deactivationUrl).toBe('sudo docker run --device=/dev/mei0 rpc:latest -u wss://' + new URL(environment.rpsServer).hostname + '/activate ')
   })
 
   it('should set the isCopied flag to true on click of copy icon ', fakeAsync(() => {

@orinem
Copy link
Contributor Author

orinem commented Aug 5, 2022

A perhaps simpler fix would be to set environment.rpsServer to 'http://localhost:8081' in beforeEach(() => { ... })

@rjbrache rjbrache added the good first issue Good for newcomers label Aug 10, 2022
@matt-primrose matt-primrose moved this to 🆕 New in Feature Backlog Nov 9, 2022
@matt-primrose matt-primrose added the P3 Priority 3 - Low label Jul 16, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
good first issue Good for newcomers P3 Priority 3 - Low
Projects
Status: No status
Development

No branches or pull requests

3 participants