device-management-toolkit / device-management-toolkit/sample-web-ui

Tests fail if RPS server isn't localhost

Open
#808 1 comment 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

good first issue P3
Dominant language
TypeScript
Stars
13
Forks
19
Avg merge
1d 1h
Merged PRs (30d)
49

Description

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(() => {

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start with src/app/shared/deactivate-device/deactivate-device.component.spec.ts and compare its hardcoded localhost expectations with src/environments/environment.ts. Run the tests using a remote RPS server configuration; done means the deactivation URL tests pass without assuming localhost.

Written by the indexing model from the issue text.

Assessment

Tech stack
angular, typescript
Domain
frontend, testing
Issue type
Bug
Difficulty
2/5
Estimated time
1-3 hours
Activity status
Stale
Clarity
Clearly specified
Newbie friendliness
38/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.