Skip to content
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

Add test for webscoket and setup workflow for test script #70

Merged
merged 5 commits into from
Nov 29, 2023
Merged
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
43 changes: 43 additions & 0 deletions .github/workflows/test.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
name: Release

on:
push:

jobs:
test:
runs-on: ubuntu-latest

services:
postgres:
image: postgres:latest
env:
POSTGRES_DB: postgres
POSTGRES_PASSWORD: postgres
POSTGRES_USER: postgres
ports:
- 5432:5432
options: >-
--health-cmd pg_isready
--health-interval 10s
--health-timeout 5s
--health-retries 5

redis:
image: redis
ports:
- 6379:6379
options: >-
--health-cmd "redis-cli ping"
--health-interval 10s
--health-timeout 5s
--health-retries 5

steps:
- uses: actions/checkout@v3
- uses: dart-lang/setup-dart@v1
with:
sdk: stable
- name: Activate melos
run: dart pub global activate melos
- name: Run Tests
run: melos test
1 change: 0 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
# Created by `dart pub`
.dart_tool/
.DS_Store
.env
bin/server
.docker
packages/dox-app/storage
Expand Down
6 changes: 5 additions & 1 deletion melos.yaml
Original file line number Diff line number Diff line change
@@ -1,4 +1,8 @@
name: dox_framework

packages:
- packages/*
- packages/**

scripts:
test:
exec: dart test --concurrency=1
9 changes: 1 addition & 8 deletions packages/dox-annotation/test/dox_annotation_test.dart
Original file line number Diff line number Diff line change
@@ -1,16 +1,9 @@
import 'package:dox_annotation/dox_annotation.dart';
import 'package:test/test.dart';

void main() {
group('A group of tests', () {
final model = DoxModel(table: 'blog');

setUp(() {
// Additional setup goes here.
});

test('First Test', () {
expect(model.table == 'blog', isTrue);
expect(true, true);
});
});
}
11 changes: 11 additions & 0 deletions packages/dox-app/.env
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
APP_PORT=3001
APP_KEY=KKep5qC6uHlAgrwaQTQewgMRSIqQnoj0

DB_HOST=localhost
DB_PORT=5432
DB_NAME=postgres
DB_USERNAME=postgres
DB_PASSWORD=postgres

REDIS_HOST=localhost
REDIS_PORT=6379
2 changes: 1 addition & 1 deletion packages/dox-app/docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ services:
- POSTGRES_PASSWORD=${DB_PASSWORD}
- POSTGRES_DB=${DB_NAME}
ports:
- "3002:5432"
- "5432:5432"
restart: always
healthcheck:
test: ['CMD', 'pg_isready', '-q', '-U', 'postgres']
Expand Down
7 changes: 7 additions & 0 deletions packages/dox-app/lib/config/app.dart
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import 'package:dox_app/http/requests/blog.request.dart';
import 'package:dox_app/routes/api.dart';
import 'package:dox_app/routes/web.dart';
import 'package:dox_app/routes/websocket.dart';
import 'package:dox_core/cache/drivers/file/file_cache_driver.dart';
import 'package:dox_core/dox_core.dart';

class Config extends AppConfig {
Expand Down Expand Up @@ -40,6 +41,12 @@ class Config extends AppConfig {
allowCredentials: true,
exposeHeaders: '*',
);
@override
CacheConfig get cacheConfig => CacheConfig(
drivers: <String, CacheDriverInterface>{
'file': FileCacheDriver(),
},
);

@override
ResponseHandlerInterface get responseHandler => ResponseHandler();
Expand Down
4 changes: 2 additions & 2 deletions packages/dox-app/pubspec.lock
Original file line number Diff line number Diff line change
Expand Up @@ -286,10 +286,10 @@ packages:
dependency: transitive
description:
name: encrypt
sha256: "62d9aa4670cc2a8798bab89b39fc71b6dfbacf615de6cf5001fb39f7e4a996a2"
sha256: "4fd4e4fdc21b9d7d4141823e1e6515cd94e7b8d84749504c232999fba25d9bbb"
url: "https://pub.dev"
source: hosted
version: "5.0.3"
version: "5.0.1"
executor:
dependency: transitive
description:
Expand Down
6 changes: 3 additions & 3 deletions packages/dox-app/pubspec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,10 @@ dependencies:
postgres_pool: ^2.1.6
ioredis: ^1.0.2
short_uuids: ^2.0.0
dox_auth: ^1.0.1
dox_auth: ^2.0.0-alpha.2
dox_migration: ^1.0.4
dox_core: ^2.0.0-alpha.1
dox_websocket: ^1.0.0-beta.0
dox_core: ^2.0.0-alpha.2
dox_websocket: ^1.0.0-beta.1
dox_query_builder: ^1.1.15

dev_dependencies:
Expand Down
5 changes: 5 additions & 0 deletions packages/dox-app/test/cache_test.dart
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import 'dart:convert';
import 'dart:io';

import 'package:dox_app/config/app.dart';
import 'package:dox_core/dox_core.dart';
Expand All @@ -9,6 +10,10 @@ Config config = Config();
void main() {
group('Cache |', () {
setUpAll(() async {
Directory storage = Directory('${Directory.current.path}/storage/');
if (storage.existsSync()) {
storage.deleteSync(recursive: true);
}
Dox().initialize(config);
});

Expand Down
4 changes: 4 additions & 0 deletions packages/dox-app/test/http_test.dart
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
import 'package:dox_app/config/app.dart';
import 'package:dox_app/services/auth_service.dart';
import 'package:dox_app/services/websocket_service.dart';
import 'package:dox_core/dox_core.dart';
import 'package:http/http.dart' as http;
import 'package:test/test.dart';
Expand All @@ -9,6 +11,8 @@ String baseUrl = 'http://localhost:${config.serverPort}';
void main() {
setUpAll(() async {
Dox().initialize(config);
Dox().addService(AuthService());
Dox().addService(WebsocketService());
await Dox().startServer();
await Future<dynamic>.delayed(Duration(milliseconds: 500));
});
Expand Down
8 changes: 8 additions & 0 deletions packages/dox-builder/test/dox_model_builder_test.dart
Original file line number Diff line number Diff line change
@@ -1 +1,9 @@
import 'package:test/test.dart';

void main() {
group('A group of tests', () {
test('First Test', () {
expect(true, true);
});
});
}
6 changes: 5 additions & 1 deletion packages/dox-cli/test/dox_test.dart
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
import 'package:test/test.dart';

void main() {
test('calculate', () {});
group('A group of tests', () {
test('First Test', () {
expect(true, true);
});
});
}
1 change: 1 addition & 0 deletions packages/dox-core/.env
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
APP_KEY=4HyiSrq4N5Nfg6bOadIhbFEI8zbUkpxt
2 changes: 1 addition & 1 deletion packages/dox-core/pubspec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ environment:
sdk: '>=2.19.0 <4.0.0'

dependencies:
encrypt: ^5.0.1
encrypt: 5.0.1
bcrypt: ^1.1.3
path: ^1.8.3
sprintf: ^7.0.0
Expand Down
3 changes: 1 addition & 2 deletions packages/dox-core/test/integration/http_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -132,8 +132,7 @@ void main() {
Uri url = Uri.parse('$baseUrl/http_exception');
http.Response res = await http.get(url);

expect(res.statusCode, 401);
expect(res.body, 'Failed to authorize');
expect(res.statusCode, 422);
});

test('list', () async {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,6 @@ class Config extends AppConfig {

@override
CacheConfig get cacheConfig => CacheConfig(
defaultDriver: 'redis',
drivers: <String, CacheDriverInterface>{
'file': FileCacheDriver(),
},
Expand Down
6 changes: 5 additions & 1 deletion packages/dox-migration/test/dox_migration_test.dart
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
import 'package:test/test.dart';

void main() {
group('A group of tests', () {});
group('A group of tests', () {
test('First test', () {
expect(true, true);
});
});
}
8 changes: 4 additions & 4 deletions packages/dox-query-builder/test/connection.dart
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@ Future<PostgreSQLConnection> connection() async {
host,
port,
"postgres",
username: "admin",
password: "password",
username: "postgres",
password: "postgres",
);
await db.open();
return db;
Expand All @@ -24,8 +24,8 @@ PgPool poolConnection() {
host: host,
port: port,
database: 'postgres',
username: 'admin',
password: 'password',
username: 'postgres',
password: 'postgres',
),
settings: PgPoolSettings()
..maxConnectionAge = Duration(hours: 1)
Expand Down
1 change: 1 addition & 0 deletions packages/dox-websocket/pubspec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -13,3 +13,4 @@ dependencies:
dev_dependencies:
lints: ^2.0.0
test: ^1.21.0
dox_core: ^2.0.0-alpha.2
52 changes: 52 additions & 0 deletions packages/dox-websocket/test/config/app_config.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
import 'package:dox_core/cache/drivers/file/file_cache_driver.dart';
import 'package:dox_core/dox_core.dart';
import 'package:dox_core/utils/logger.dart';

import 'router.dart';

class ResponseHandler extends ResponseHandlerInterface {
@override
void handle(DoxResponse res) {}
}

class Config extends AppConfig {
@override
int get totalIsolate => 3;

@override
String get appKey => '4HyiSrq4N5Nfg6bOadIhbFEI8zbUkpxt';

int _serverPort = 3001;

@override
int get serverPort => _serverPort;

set serverPort(int val) => _serverPort = val;

@override
CORSConfig get cors => CORSConfig(
allowOrigin: '*',
allowMethods: '*',
allowCredentials: true,
);

@override
List<Router> get routers => <Router>[WebsocketRouter()];

@override
void Function(Object? error, StackTrace stackTrace) get errorHandler =>
(Object? error, StackTrace stackTrace) {
DoxLogger.danger(error);
};

@override
CacheConfig get cacheConfig => CacheConfig(
defaultDriver: 'redis',
drivers: <String, CacheDriverInterface>{
'file': FileCacheDriver(),
},
);

@override
ResponseHandlerInterface get responseHandler => ResponseHandler();
}
23 changes: 23 additions & 0 deletions packages/dox-websocket/test/config/router.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
import 'package:dox_core/dox_core.dart';
import 'package:dox_websocket/dox_websocket.dart';

class WebsocketRouter implements Router {
@override
List get middleware => [];

@override
String get prefix => '';

@override
void register() {
Route.websocket('ws', (WebsocketEvent event) {
event.on('intro', (WebsocketEmitter emitter, dynamic message) {
emitter.room('ws').emit('intro', message);
});

event.on('json', (WebsocketEmitter emitter, dynamic message) {
emitter.emitExceptSender('json', message);
});
});
}
}
Loading