Skip to content

Add E2E tests using vitest #583

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

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 15 additions & 0 deletions .env.example
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
# Example environment variables for API authentication

# DHIS2 API
DHIS2_BASE_URL=https://play.dhis2.org/40.0.0
DHIS2_USERNAME=admin
DHIS2_PASSWORD=district

# Netlify API
NETLIFY_API_TOKEN=your_netlify_api_token

# Vercel API
VERCEL_API_TOKEN=your_vercel_api_token

# Zoom API
ZOOM_API_TOKEN=your_zoom_api_token
34 changes: 34 additions & 0 deletions .github/workflows/e2e-tests.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
name: E2E Tests

on:
push:
branches:
- main
pull_request:

jobs:
e2e-tests:
name: E2E Tests
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4

- name: Configure
run: |
echo ::set-output name=NVMRC::$(cat .nvmrc)
id: config

- name: Install pnpm
uses: pnpm/action-setup@v4

- name: Use Node.js ${{ steps.config.outputs.NVMRC }}
uses: actions/setup-node@v4
with:
node-version: ${{ steps.config.outputs.NVMRC }}
cache: 'pnpm'

- name: Install dependencies
run: pnpm install

- name: Run E2E Tests
run: pnpm vitest
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,4 @@ node_modules
dist
*.log
.turbo
.env
38 changes: 38 additions & 0 deletions packages/dhis2-openapi/test/e2e.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
import { describe, it, expect, beforeAll } from 'vitest';
import { DHIS2Client } from '../dist';
import dotenv from 'dotenv';

dotenv.config();

describe('DHIS2 OpenAPI E2E Tests', () => {
let client: DHIS2Client;

beforeAll(() => {
const baseUrl = process.env.DHIS2_BASE_URL;
const username = process.env.DHIS2_USERNAME;
const password = process.env.DHIS2_PASSWORD;

if (!baseUrl || !username || !password) {
throw new Error('Missing environment variables for DHIS2 API');
}

client = new DHIS2Client({
baseUrl,
credentials: {
type: 'basic',
username,
password,
},
});
});

it('should compile the package correctly', () => {
expect(client).toBeDefined();
});

it('should connect and authenticate against the DHIS2 API', async () => {
const response = await client.get('/me');
expect(response).toBeDefined();
expect(response.status).toBe(200);
});
});
31 changes: 31 additions & 0 deletions packages/netlify-api/test/e2e.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
import { describe, it, expect, beforeAll } from 'vitest';
import { NetlifyClient } from '../dist';
import dotenv from 'dotenv';

dotenv.config();

describe('Netlify API E2E Tests', () => {
let client: NetlifyClient;

beforeAll(() => {
const token = process.env.NETLIFY_API_TOKEN;

if (!token) {
throw new Error('Missing environment variable for Netlify API');
}

client = new NetlifyClient({
token,
});
});

it('should compile the package correctly', () => {
expect(client).toBeDefined();
});

it('should connect and authenticate against the Netlify API', async () => {
const response = await client.get('/user');
expect(response).toBeDefined();
expect(response.status).toBe(200);
});
});
31 changes: 31 additions & 0 deletions packages/vercel-api-js/test/e2e.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
import { describe, it, expect, beforeAll } from 'vitest';
import { VercelApi } from '../dist';
import dotenv from 'dotenv';

dotenv.config();

describe('Vercel API E2E Tests', () => {
let client: VercelApi;

beforeAll(() => {
const token = process.env.VERCEL_API_TOKEN;

if (!token) {
throw new Error('Missing environment variable for Vercel API');
}

client = new VercelApi({
token,
});
});

it('should compile the package correctly', () => {
expect(client).toBeDefined();
});

it('should connect and authenticate against the Vercel API', async () => {
const response = await client.get('/v1/projects');
expect(response).toBeDefined();
expect(response.status).toBe(200);
});
});
22 changes: 22 additions & 0 deletions packages/zoom-api-js/test/e2e.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
import { describe, it, expect, beforeAll } from 'vitest';
import { ZoomApi } from '../dist';

describe('Zoom API E2E Tests', () => {
let zoomApi: ZoomApi;

beforeAll(() => {
require('dotenv').config();
const token = process.env.ZOOM_API_TOKEN;
zoomApi = new ZoomApi({ token });
});

it('should compile the package well', () => {
expect(zoomApi).toBeDefined();
});

it('should connect and authenticate against the API', async () => {
const response = await zoomApi.request('GET /users/me', {});
expect(response).toBeDefined();
expect(response.id).toBeDefined();
});
});
Loading