Skip to content

Commit

Permalink
add config as env
Browse files Browse the repository at this point in the history
Signed-off-by: Erick Wendel <[email protected]>
  • Loading branch information
ErickWendel committed Jul 29, 2024
1 parent 2732a1f commit d6f094a
Show file tree
Hide file tree
Showing 4 changed files with 33 additions and 29 deletions.
5 changes: 2 additions & 3 deletions .github/workflows/run-tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -32,9 +32,6 @@ jobs:
- name: Start nodered
run: npm run docker:start-nodered

- name: Create spreadsheets.json
run: echo "${{ secrets.GOOGLE_SHEETS_AUTH_FILE }}" > spreadsheets.json

- name: Restore dependencies
run: npm ci

Expand All @@ -46,6 +43,8 @@ jobs:

- name: Run Playwright tests
run: npm run playwright:headless
env:
GOOGLE_SHEETS_AUTH_FILE: ${{ secrets.GOOGLE_SHEETS_AUTH_FILE }}

- uses: actions/upload-artifact@v4
if: always()
Expand Down
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# Logs
spreadsheet.json
spreadsheets.json
misc/data/
creds.json
logs
Expand Down
3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,8 @@
"docker:restart-nodered-on-change": "nodemon -e html,js,json,css --exec 'npm run copy-files && cd misc && npm run docker:restart-nodered && docker logs -f nodered'",
"playwright:web": "npx playwright test --ui --debug",
"playwright:headless": "npx playwright test",
"test": "npm run playwright:headless"
"test": "npm run playwright:headless",
"test:dev": "export GOOGLE_SHEETS_AUTH_FILE=$(cat spreadsheets.json) && npm run playwright:headless"
},
"author": "erickwendel",
"keywords": [
Expand Down
52 changes: 28 additions & 24 deletions tests/e2e/app.spec.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
// @ts-nocheck

const spreadsheet = require('../../spreadsheet.json');
console.assert(process.env.GOOGLE_SHEETS_AUTH_FILE, 'env GOOGLE_SHEETS_AUTH_FILE is required!')

// @ts-ignore
const spreadsheets = JSON.parse(process.env.GOOGLE_SHEETS_AUTH_FILE)

const { test, expect } = require('@playwright/test')
const { describe, beforeEach, afterAll, beforeAll } = test;

Expand Down Expand Up @@ -45,13 +49,13 @@ describe('Node-RED Interface', () => {
await page.goto(NODERED_URL);
})

const firstSheet = spreadsheet.sheets.at(0)
const secondSheet = spreadsheet.sheets.at(1)
const firstSheet = spreadsheets.sheets.at(0)
const secondSheet = spreadsheets.sheets.at(1)

const firstSheetColumns = JSON.stringify(firstSheet.columns)
const secondSheetColumns = JSON.stringify(secondSheet.columns)

const sheetsNames = spreadsheet.sheets.map(item => item.name)
const sheetsNames = spreadsheets.sheets.map(item => item.name)

describe('should create a flow with an API and setup sheets', () => {

Expand Down Expand Up @@ -79,11 +83,11 @@ describe('Node-RED Interface', () => {
const node = page.locator(`#${sheetsToJsonStreamNode}`)
await node.waitFor();
await node.dblclick();
await editor.addValidConfig(spreadsheet.googleAuthCredentials);
await editor.addValidConfig(spreadsheets.googleAuthCredentials);
});

await test.step(`And I enter the spreadsheet ID "${spreadsheet.spreadsheetId}" and leave the input field`, async () => {
await editor.elements.sheetsToJSON.sheetIdInput().type(spreadsheet.spreadsheetId);
await test.step(`And I enter the spreadsheet ID "${spreadsheets.spreadsheetId}" and leave the input field`, async () => {
await editor.elements.sheetsToJSON.sheetIdInput().type(spreadsheets.spreadsheetId);
await editor.elements.sheetsToJSON.sheetIdInput().press('Tab');
});

Expand Down Expand Up @@ -145,9 +149,9 @@ describe('Node-RED Interface', () => {
const expectedRange = firstSheet.range.split(':').at(0).concat(`:${columnLetter}${linesToConsume}`)

const flow = generateTCPFlowWithCompleteData({
sheets: spreadsheet.sheets,
spreadsheetId: spreadsheet.spreadsheetId,
googleAuthCredentials: spreadsheet.googleAuthCredentials,
sheets: spreadsheets.sheets,
spreadsheetId: spreadsheets.spreadsheetId,
googleAuthCredentials: spreadsheets.googleAuthCredentials,
tcpPort: TCP_PORT,
})

Expand Down Expand Up @@ -228,9 +232,9 @@ describe('Node-RED Interface', () => {
const expectedRange = firstSheet.range.split(':').at(0).concat(`:${columnLetter}${linesToConsume}`)

const flow = generateTCPFlowWithCompleteData({
sheets: spreadsheet.sheets,
spreadsheetId: spreadsheet.spreadsheetId,
googleAuthCredentials: spreadsheet.googleAuthCredentials,
sheets: spreadsheets.sheets,
spreadsheetId: spreadsheets.spreadsheetId,
googleAuthCredentials: spreadsheets.googleAuthCredentials,
tcpPort: TCP_PORT,
})

Expand Down Expand Up @@ -321,11 +325,11 @@ describe('Node-RED Interface', () => {
await node.waitFor();

await node.dblclick();
await editor.addValidConfig(spreadsheet.googleAuthCredentials);
await editor.addValidConfig(spreadsheets.googleAuthCredentials);
});

await test.step(`And I enter the spreadsheet ID "${spreadsheet.spreadsheetId}" and leave the input field`, async () => {
await editor.elements.sheetsToJSON.sheetIdInput().type(spreadsheet.spreadsheetId);
await test.step(`And I enter the spreadsheet ID "${spreadsheets.spreadsheetId}" and leave the input field`, async () => {
await editor.elements.sheetsToJSON.sheetIdInput().type(spreadsheets.spreadsheetId);
await editor.elements.sheetsToJSON.sheetIdInput().press('Tab');
});

Expand Down Expand Up @@ -366,8 +370,8 @@ describe('Node-RED Interface', () => {
const editor = new NodeRedEditor({ page });
const flow = generatePreviouslyCreatedSheetsToJSON({
sheets: [secondSheet, firstSheet],
spreadsheetId: spreadsheet.spreadsheetId,
googleAuthCredentials: spreadsheet.googleAuthCredentials,
spreadsheetId: spreadsheets.spreadsheetId,
googleAuthCredentials: spreadsheets.googleAuthCredentials,
})

await test.step('Given I insert a complete flow using sheets-to-json node and a valid config', async () => {
Expand All @@ -391,7 +395,7 @@ describe('Node-RED Interface', () => {

await test.step(`Then the fields should contain data for spreadsheet id`, async () => {
const input = await editor.elements.sheetsToJSON.sheetIdInput()
await expect(input).toHaveValue(spreadsheet.spreadsheetId)
await expect(input).toHaveValue(spreadsheets.spreadsheetId)
});

await test.step(`And the range field should be ${secondSheet.range}`, async () => {
Expand All @@ -409,7 +413,7 @@ describe('Node-RED Interface', () => {

expect(options).toStrictEqual([
secondSheet.name,
spreadsheet.sheets.at(0).name
spreadsheets.sheets.at(0).name
]);
});

Expand Down Expand Up @@ -438,8 +442,8 @@ describe('Node-RED Interface', () => {
const editor = new NodeRedEditor({ page });
const flow = generatePreviouslyCreatedSheetsToJSON({
sheets: [secondSheet, firstSheet],
spreadsheetId: spreadsheet.spreadsheetId,
googleAuthCredentials: spreadsheet.googleAuthCredentials,
spreadsheetId: spreadsheets.spreadsheetId,
googleAuthCredentials: spreadsheets.googleAuthCredentials,
})

await test.step('Given I insert a complete flow using sheets-to-json node and a valid config', async () => {
Expand Down Expand Up @@ -517,8 +521,8 @@ describe('Node-RED Interface', () => {
const editor = new NodeRedEditor({ page });
const flow = generatePreviouslyCreatedSheetsToJSON({
sheets: [secondSheet, firstSheet],
spreadsheetId: spreadsheet.spreadsheetId,
googleAuthCredentials: spreadsheet.googleAuthCredentials,
spreadsheetId: spreadsheets.spreadsheetId,
googleAuthCredentials: spreadsheets.googleAuthCredentials,
})


Expand Down

0 comments on commit d6f094a

Please sign in to comment.