Signed-off-by: Jasmin <jasmin@hardcoreeng.com>
This commit is contained in:
JasminMus 2024-07-03 08:53:10 +02:00 committed by GitHub
parent 95d4effca7
commit 73afaddc65
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
6 changed files with 155 additions and 0 deletions

43
.github/workflows/integrations.yml vendored Normal file
View File

@ -0,0 +1,43 @@
name: GithubIntegrations
on:
schedule:
# Runs at 5 AM UTC every day. We can change this to whatever we need or want
- cron: '0 5 * * *'
jobs:
setup-and-test:
runs-on: ubuntu-latest
timeout-minutes: 60
steps:
- name: Checkout repository
uses: actions/checkout@v4
with:
fetch-depth: 0
- name: Setup Node.js
uses: actions/setup-node@v4
with:
node-version-file: '.nvmrc'
- name: Cache node modules
uses: actions/cache@v4
with:
path: |
common/temp
key: ${{ runner.os }}-build-node-${{ hashFiles('**/pnpm-lock.yaml') }}
restore-keys: |
${{ runner.os }}-build-node-${{ hashFiles('**/pnpm-lock.yaml') }}
- name: Checking for mis-matching dependencies...
run: node common/scripts/install-run-rush.js check
- name: Installing...
run: node common/scripts/install-run-rush.js install
- name: Install Playwright
run: |
cd ./tests/sanity
node ../../common/scripts/install-run-rushx.js ci
- name: Run UI tests
run: |
cd ./tests/sanity
node ../../common/scripts/install-run-rushx.js staging-uitest
env:
TESTING_GH_TOKEN: ${{ secrets.TESTING_GH_TOKEN }}
TESTING_GH_OWNER: ${{ secrets.TESTING_GH_OWNER }}

View File

@ -1,5 +1,6 @@
PLATFORM_URI='http://localhost:8083' PLATFORM_URI='http://localhost:8083'
PLATFORM_TRANSACTOR='ws://localhost:3334' PLATFORM_TRANSACTOR='ws://localhost:3334'
STAGING_URL='https://front.hc.engineering'
PLATFORM_USER='user1' PLATFORM_USER='user1'
PLATFORM_USER_SECOND='user2' PLATFORM_USER_SECOND='user2'
PLATFORM_TOKEN='eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJlbWFpbCI6InVzZXIxIiwid29ya3NwYWNlIjoic2FuaXR5LXdzIn0.hfUCqePHO-WNps2by4B-CYGKIpDpLG0WVCUUtU-SVI4' PLATFORM_TOKEN='eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJlbWFpbCI6InVzZXIxIiwid29ya3NwYWNlIjoic2FuaXR5LXdzIn0.hfUCqePHO-WNps2by4B-CYGKIpDpLG0WVCUUtU-SVI4'

View File

@ -20,6 +20,7 @@
"ci": "playwright install --with-deps chromium", "ci": "playwright install --with-deps chromium",
"test": "", "test": "",
"uitest": "cross-env LOCAL_URL=http://localhost:3003/ DEV_URL= playwright test -c ./tests/playwright.config.ts", "uitest": "cross-env LOCAL_URL=http://localhost:3003/ DEV_URL= playwright test -c ./tests/playwright.config.ts",
"staging-uitest": "cross-env PLATFORM_URI=https://front.hc.engineering/ playwright test -c ./tests/playwright.config.ts --grep @staging",
"dev-uitest": "cross-env PLATFORM_URI=http://localhost:8080 PLATFORM_TRANSACTOR=ws://localhost:3333 SETTING=storage-dev.json SETTING_SECOND=storageSecond-dev.json DEV_URL=http://localhost:8080/account playwright test -c ./tests/playwright.config.ts", "dev-uitest": "cross-env PLATFORM_URI=http://localhost:8080 PLATFORM_TRANSACTOR=ws://localhost:3333 SETTING=storage-dev.json SETTING_SECOND=storageSecond-dev.json DEV_URL=http://localhost:8080/account playwright test -c ./tests/playwright.config.ts",
"debug": "playwright test -c ./tests/playwright.config.ts --debug --headed", "debug": "playwright test -c ./tests/playwright.config.ts --debug --headed",
"dev-debug": "cross-env PLATFORM_URI=http://localhost:8080 PLATFORM_TRANSACTOR=ws://localhost:3333 SETTING=storage-dev.json SETTING_SECOND=storageSecond-dev.json playwright test -c ./tests/playwright.config.ts --debug --headed", "dev-debug": "cross-env PLATFORM_URI=http://localhost:8080 PLATFORM_TRANSACTOR=ws://localhost:3333 SETTING=storage-dev.json SETTING_SECOND=storageSecond-dev.json playwright test -c ./tests/playwright.config.ts --debug --headed",

View File

@ -0,0 +1,76 @@
import { APIRequestContext } from '@playwright/test'
export class GithubIntegration {
private readonly request: APIRequestContext
private readonly baseUrl: string
private readonly githubToken: string
private readonly repoOwner: string
constructor (request: APIRequestContext) {
this.request = request
this.baseUrl = 'https://api.github.com'
this.githubToken = process.env.TESTING_GH_TOKEN as string
this.repoOwner = process.env.TESTING_GH_OWNER as string
if (typeof this.githubToken !== 'string' || this.githubToken.trim() === '') {
throw new Error('Environment variable TESTING_GH_TOKEN is not set or empty.')
}
if (typeof this.repoOwner !== 'string' || this.repoOwner.trim() === '') {
throw new Error('Environment variable TESTING_GH_OWNER is not set or empty.')
}
}
async createGitHubRepository (repoName: string, description: string = '', isPrivate: boolean = false): Promise<any> {
const githubToken = this.githubToken
const url = `${this.baseUrl}/user/repos`
const payload = {
name: repoName,
description,
private: isPrivate
}
const headers = {
Authorization: `token ${githubToken}`,
Accept: 'application/vnd.github.v3+json',
'Content-Type': 'application/json'
}
const response = await this.request.post(url, { data: payload, headers })
if (response.status() !== 201) {
throw new Error(`Failed to create repository: ${response.status()} ${response.statusText()}`)
}
return await response.json()
}
async createGitHubIssue (repoName: string, issueTitle: string, issueBody: string): Promise<any> {
const githubToken = this.githubToken
const url = `${this.baseUrl}/repos/${this.repoOwner}/${repoName}/issues`
const payload = {
title: issueTitle,
body: issueBody
}
const headers = {
Authorization: `token ${githubToken}`,
Accept: 'application/vnd.github.v3+json',
'Content-Type': 'application/json'
}
const response = await this.request.post(url, { data: payload, headers })
if (response.status() !== 201) {
throw new Error(`Failed to create issue: ${response.status()} ${response.statusText()}`)
}
return await response.json()
}
async deleteGitHubRepository (repoName: string): Promise<void> {
const githubToken = this.githubToken
const url = `${this.baseUrl}/repos/${this.repoOwner}/${repoName}`
const headers = {
Authorization: `token ${githubToken}`,
Accept: 'application/vnd.github.v3+json',
'Content-Type': 'application/json'
}
const response = await this.request.delete(url, { headers })
if (response.status() !== 204) {
throw new Error(`Failed to delete repository: ${response.status()} ${response.statusText()}`)
}
}
}

View File

@ -0,0 +1,33 @@
import { test } from '@playwright/test'
// import { LoginPage } from '../model/login-page'
import { StagingUrl } from '../utils'
// import { CommonTrackerPage } from '../model/tracker/common-tracker-page'
// import { SignUpPage } from '../model/signup-page'
// import { TrackerNavigationMenuPage } from '../model/tracker/tracker-navigation-menu-page'
// import { SelectWorkspacePage } from '../model/select-workspace-page'
// import { GithubIntegration } from '../API/GithubIntegration'
// import { faker } from '@faker-js/faker'
test.describe('Github integrations @staging', () => {
// let githubIntegrations: GithubIntegration
test.beforeEach(async ({ page, request }) => {
// loginPage = new LoginPage(page)
// commonTrackerPage = new CommonTrackerPage(page)
// signupPage = new SignUpPage(page)
// trackerNavigationMenuPage = new TrackerNavigationMenuPage(page)
// selectWorkspacePage = new SelectWorkspacePage(page)
// githubIntegrations = new GithubIntegration(request)
// const repoName = faker.word.words(1)
// const issueTitle = faker.word.words(4)
// const issueBody = faker.word.words(10)
// await githubIntegrations.createGitHubRepository(repoName)
// await githubIntegrations.createGitHubIssue(repoName, issueTitle, issueBody)
await (await page.goto(`${StagingUrl}`))?.finished()
await page.waitForTimeout(100)
// await githubIntegrations.deleteGitHubRepository(repoName)
})
test('user can integrate using github @staging', async ({ page }) => {})
})

View File

@ -13,6 +13,7 @@ export const PlatformSettingSecond = process.env.SETTING_SECOND as string
export const DefaultWorkspace = 'SanityTest' export const DefaultWorkspace = 'SanityTest'
export const LocalUrl = process.env.LOCAL_URL as string export const LocalUrl = process.env.LOCAL_URL as string
export const DevUrl = process.env.DEV_URL as string export const DevUrl = process.env.DEV_URL as string
export const StagingUrl = process.env.STAGING_URL as string
export function generateTestData (): TestData { export function generateTestData (): TestData {
const generateWordStartingWithA = (): string => { const generateWordStartingWithA = (): string => {