Skip to content

Commit

Permalink
Create node.js.yml (#63)
Browse files Browse the repository at this point in the history
* Create node.js.yml

Git hub actions for Sample App tests

* update

* added time out

* supported Node.js

* formatting

* formatting

* formatting

* formatting

* formatting

* formatting

* formatting

* changes

* changes

* changes

* changes

* changes

* changes

* changes

* changes

* changes

* changes

* changes

* changes

* changes

* changes

* mock cors

* config

* changes

* changes

* changes

* changes

* changes

* changes

* changes

* changes

* changes

* changes

* changes

* changes

* last changes
  • Loading branch information
olamidekumapayisonos authored Aug 25, 2023
1 parent 402b1f2 commit 14eb777
Show file tree
Hide file tree
Showing 13 changed files with 242 additions and 13 deletions.
49 changes: 49 additions & 0 deletions .github/workflows/node.js.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
name: Node.js CI

on:
push:
branches: [ "main" ]
pull_request:
branches: [ "main" ]

jobs:
build:

runs-on: [self-hosted, bionic]
timeout-minutes: 10
defaults:
run:
working-directory: 'sample-app/Client'

steps:
- uses: actions/checkout@v3

# TEMPORARY until we get a runner on ubuntu focal (20.4) or jammy (22.4)
- name: Install Sonos Node
run: |
wget https://packages.sonos.com/bootstrap-no-check.sh
chmod +x bootstrap-no-check.sh
sudo ./bootstrap-no-check.sh
sudo apt install -y sonos-nodejs-18.12.1
sudo rm /usr/bin/node
sudo ln -s /usr/local/nodejs-18.12.1/bin/node /usr/bin/node
sudo rm /usr/bin/npm
sudo ln -s /usr/local/nodejs-18.12.1/bin/npm /usr/bin/npm
# Proper way to setup node once we have a more updated ubuntu runner
# - name: Setup Node
# uses: actions/setup-node@v3
# with: ${{ env.NODE_VERSION }}

- name: Install dependencies
run: npm ci
working-directory: 'sample-app/Client'

- name: Run mock Server
run: node mock-cors.js &
working-directory: 'sample-app/Test-cors'

- name: Run tests
run: npm test
working-directory: 'sample-app/Client'
File renamed without changes.
16 changes: 11 additions & 5 deletions sample-app/Client/src/App/UnitTests/getGroups.test.js
Original file line number Diff line number Diff line change
@@ -1,17 +1,23 @@
import { render } from "@testing-library/react";
import { render, screen } from "@testing-library/react";
import GetGroups from "../UserDetails/getGroups";
import { Configuration } from "../museClient/configuration";
import testConfig from "./testConfig.json";
import {RecoilRoot} from 'recoil';
import '@testing-library/jest-dom';

test("testing the getGroups API", () => {
const testHouseholdID = testConfig.householdID;
const testMuseClientConfig = new Configuration({
accessToken: testConfig.authToken
});
render(
<GetGroups
householdId={testHouseholdID}
museClientConfig={testMuseClientConfig}
/>
<RecoilRoot>
<GetGroups
showLoadingScreen={true}
householdId={testHouseholdID}
museClientConfig={testMuseClientConfig}
/>
</RecoilRoot>
);
expect(screen.getByTestId('custom-element')).toBeVisible();
});
4 changes: 4 additions & 0 deletions sample-app/Client/src/App/UnitTests/getHouseholdID.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,12 @@ test("testing the getHouseholds API", () => {
const testMuseClientConfig = new Configuration({
accessToken: testConfig.authToken
});
hh_handler = () => {
};

render(
<GetHouseholds
hh_handler={hh_handler}
museClientConfig={testMuseClientConfig}
/>
);
Expand Down
2 changes: 1 addition & 1 deletion sample-app/Client/src/App/UserDetails/getGroups.js
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ export default function GetGroups(props) {
) : props.showLoadingScreen && (
<div className="main_page">
<div className="render_page">
<CircularProgress color="inherit" />
<CircularProgress color="inherit" data-testid="custom-element"/>
</div>
</div>
);
Expand Down
2 changes: 1 addition & 1 deletion sample-app/Client/src/App/museClient/OAS_production.json
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@
},
"servers": [
{
"url": "http://localhost:8090/https://api.ws.sonos.com/control/api/v2",
"url": "http://127.0.0.1:8090/https://api.ws.sonos.com/control/api/v2",

"description": "Full api URI",
"variables": {
Expand Down
2 changes: 1 addition & 1 deletion sample-app/Client/src/App/museClient/api.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
*/
import * as url from "url";
import isomorphicFetch from "isomorphic-fetch";
const BASE_PATH = "http://localhost:8090/https://api.ws.sonos.com/control/api/v2".replace(/\/+$/, "");
const BASE_PATH = "http://127.0.0.1:8090/https://api.ws.sonos.com/control/api/v2".replace(/\/+$/, "");
/**
*
* @export
Expand Down
10 changes: 5 additions & 5 deletions sample-app/Client/src/config.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,11 @@
},
"apiEndPoints": {
"oauthURL":"https://api.sonos.com/login/v3/oauth?",
"createRefreshAuthTokenURL" : "http://localhost:8090/https://api.sonos.com/login/v3/oauth/access",
"householdApiURL":"http://localhost:8090/https://api.ws.sonos.com/control/api/v1/households/",
"controlApiURL":"http://localhost:8090/https://api.ws.sonos.com/control/api/v1/groups/",
"playerApiURL":"http://localhost:8090/https://api.ws.sonos.com/control/api/v1/players/"
"createRefreshAuthTokenURL" : "http://127.0.0.1:8090/https://api.sonos.com/login/v3/oauth/access",
"householdApiURL":"http://127.0.0.1:8090/https://api.ws.sonos.com/control/api/v1/households/",
"controlApiURL":"http://127.0.0.1:8090/https://api.ws.sonos.com/control/api/v1/groups/",
"playerApiURL":"http://127.0.0.1:8090/https://api.ws.sonos.com/control/api/v1/players/"
},
"socketURL":"ws://localhost:8000",
"serviceLogosURL":"http://localhost:8090/https://service-catalog.ws.sonos.com/mslogo"
"serviceLogosURL":"http://127.0.0.1:8090/https://service-catalog.ws.sonos.com/mslogo"
}
71 changes: 71 additions & 0 deletions sample-app/Test-cors/group.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
{
"_objectType": "groups",
"groups": [
{
"_objectType": "group",
"id": "RINCON_2439B3B3BDC4290:6783439021",
"name": "Sonos Roam",
"coordinatorId": "RINCON_2439B3B3BDC4290",
"playbackState": "PLAYBACK_STATE_IDLE",
"playerIds": [
"RINCON_2439B3B3BDC4290"
]
},
{
"_objectType": "group",
"id": "RINCON_2439B3B3BDC4290:6783439021",
"name": "Bedroom",
"coordinatorId": "RINCON_2439B3B3BDC4290",
"playbackState": "PLAYBACK_STATE_PLAYING",
"playerIds": [
"RINCON_2439B3B3BDC4290"
]
}
],
"players": [
{
"_objectType": "player",
"id": "RINCON_2439B3B3BDC4290",
"name": "Sonos Roam",
"websocketUrl": "wss://192.168.1.45:1443/websocket/api",
"softwareVersion": "75.1-43188-main_release",
"apiVersion": "1.36.0-alpha.10",
"minApiVersion": "1.1.0",
"isUnregistered": false,
"capabilities": [
"CLOUD",
"PLAYBACK",
"AIRPLAY",
"VOICE",
"AUDIO_CLIP"
],
"deviceIds": [
"RINCON_2439B3B3BDC4290"
]
},
{
"_objectType": "player",
"id": "RINCON_2439B3B3BDC4290",
"name": "Bedroom",
"websocketUrl": "wss://192.168.1.81:1443/websocket/api",
"softwareVersion": "76.1-43310-main_release",
"apiVersion": "1.37.0-alpha.7",
"minApiVersion": "1.1.0",
"isUnregistered": false,
"capabilities": [
"CLOUD",
"HT_PLAYBACK",
"PLAYBACK",
"HT_POWER_STATE",
"AIRPLAY",
"VOICE",
"AUDIO_CLIP",
"HDMI"
],
"deviceIds": [
"RINCON_2439B3B3BDC4290"
]
}
],
"partial": false
}
9 changes: 9 additions & 0 deletions sample-app/Test-cors/household.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
{
"households": [
{
"id": "Sonos_iHJBfvUzznmHiuYmP2aT18usVp.NoCK8hTDBL4BUwR8k2Fe",
"name": null,
"ownerLuid": "364896036"
}
]
}
26 changes: 26 additions & 0 deletions sample-app/Test-cors/mock-cors.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
const http = require('http');
const { url } = require('inspector');
const fs = require('fs')

const hostname = '127.0.0.1'
const port = 8090

const server = http.createServer((req, res) => {
res.statusCode = 200;
res.setHeader('Content-Type', 'text/plain');
if(req.url.includes('groups'))
{
//this is a mock group response statement
const fileContent = fs.readFileSync('./group.txt', 'utf-8');
res.end(fileContent);
} else {
//this is a mock household response statement
const fileContent = fs.readFileSync('./household.txt', 'utf-8');
res.end(fileContent);
}

});

server.listen(port, hostname, () => {
console.log(`Server running at http://${hostname}:${port}/`);
});
53 changes: 53 additions & 0 deletions sample-app/Test-cors/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

11 changes: 11 additions & 0 deletions sample-app/Test-cors/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
{
"dependencies": {
"cors-anywhere": "0.4.4",
"http-proxy": "1.11.1",
"proxy-from-env": "0.0.1"
},
"scripts": {
"start": "npm run server",
"server": "node cors-format.js"
}
}

0 comments on commit 14eb777

Please sign in to comment.