From ba02fbef1c60e9d953ac9016abc33c8ea6fd1f57 Mon Sep 17 00:00:00 2001 From: Mohamed Sayed Date: Mon, 10 Jan 2022 15:39:59 +0200 Subject: [PATCH] refactor - downgrade sdk + lint versions && add test cases --- .github/workflows/coverage.yml | 23 +++++++++++++++ CHANGELOG.md | 5 ++++ analysis_options.yaml | 31 +------------------- coverage/lcov.info | 25 ++++++++++++++++ example/palestine_sms_misr_example.dart | 4 +-- lib/src/palestine_sms_misr_base.dart | 8 ++---- pubspec.yaml | 5 ++-- test/palestine_sms_misr_base_test.dart | 38 +++++++++++++++++++++++++ 8 files changed, 100 insertions(+), 39 deletions(-) create mode 100644 .github/workflows/coverage.yml create mode 100644 coverage/lcov.info create mode 100644 test/palestine_sms_misr_base_test.dart diff --git a/.github/workflows/coverage.yml b/.github/workflows/coverage.yml new file mode 100644 index 0000000..22cd032 --- /dev/null +++ b/.github/workflows/coverage.yml @@ -0,0 +1,23 @@ +name: Dart CI - Test Coverage +on: + push: + branches: [main] + pull_request: + branches: [main] +jobs: + test: + defaults: + run: + working-directory: ./ + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v1 + - uses: subosito/flutter-action@v1 + with: + flutter-version: "2.8.1" + channel: "stable" + - run: flutter pub get + - run: flutter test --coverage + - uses: codecov/codecov-action@v1.0.7 + - name: Very Good Coverage + uses: VeryGoodOpenSource/very_good_coverage@v1.2.0 diff --git a/CHANGELOG.md b/CHANGELOG.md index 15e7bb2..108d24c 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,6 +2,11 @@ - Improvements. +## 0.0.7 + +- Automated Release. +- Tests. + ## 0.0.3 | 0.0.4 | 0.0.5 | 0.0.6 - release. diff --git a/analysis_options.yaml b/analysis_options.yaml index dee8927..55309e9 100644 --- a/analysis_options.yaml +++ b/analysis_options.yaml @@ -1,30 +1 @@ -# This file configures the static analysis results for your project (errors, -# warnings, and lints). -# -# This enables the 'recommended' set of lints from `package:lints`. -# This set helps identify many issues that may lead to problems when running -# or consuming Dart code, and enforces writing Dart using a single, idiomatic -# style and format. -# -# If you want a smaller set of lints you can change this to specify -# 'package:lints/core.yaml'. These are just the most critical lints -# (the recommended set includes the core lints). -# The core lints are also what is used by pub.dev for scoring packages. - -include: package:lints/recommended.yaml - -# Uncomment the following section to specify additional rules. - -# linter: -# rules: -# - camel_case_types - -# analyzer: -# exclude: -# - path/to/excluded/files/** - -# For more information about the core and recommended set of lints, see -# https://dart.dev/go/core-lints - -# For additional information about configuring this file, see -# https://dart.dev/guides/language/analysis-options +include: package:lint/analysis_options.yaml diff --git a/coverage/lcov.info b/coverage/lcov.info new file mode 100644 index 0000000..721fe35 --- /dev/null +++ b/coverage/lcov.info @@ -0,0 +1,25 @@ +SF:lib/src/palestine_sms_misr_base.dart +DA:22,1 +DA:30,1 +DA:41,1 +DA:45,2 +DA:46,1 +DA:47,5 +DA:51,4 +DA:54,1 +DA:55,3 +DA:68,1 +DA:72,1 +DA:74,2 +DA:75,1 +DA:76,6 +DA:80,4 +DA:83,1 +DA:84,3 +DA:92,1 +DA:93,1 +DA:94,3 +DA:96,1 +LF:21 +LH:21 +end_of_record diff --git a/example/palestine_sms_misr_example.dart b/example/palestine_sms_misr_example.dart index 3d42fd1..910deee 100644 --- a/example/palestine_sms_misr_example.dart +++ b/example/palestine_sms_misr_example.dart @@ -1,7 +1,7 @@ import 'package:palestine_sms_misr/palestine_sms_misr.dart'; -void main() async { - PalSMSMisr palSMSMisr = PalSMSMisr( +Future main() async { + final PalSMSMisr palSMSMisr = PalSMSMisr( userName: 'xxxxxxxx', password: 'xxxxxxxx', senderName: 'xxxxx', diff --git a/lib/src/palestine_sms_misr_base.dart b/lib/src/palestine_sms_misr_base.dart index d8ff005..f2ddc2c 100644 --- a/lib/src/palestine_sms_misr_base.dart +++ b/lib/src/palestine_sms_misr_base.dart @@ -42,14 +42,13 @@ class PalSMSMisr { required String phoneNumbers, required String message, }) async { - http.Response response = await http.post( + final http.Response response = await http.post( Uri.parse( '$baseURLMessage?username=$userName&password=$password&language=$language&sender=$senderName&mobile=$phoneNumbers&message=$message', ), ); if (response.statusCode == 200 && response.body.contains('"1901"')) { - print(response.body); return true; } else { developer.log( @@ -70,16 +69,15 @@ class PalSMSMisr { required String phoneNumber, String? code, }) async { - String _code = code ?? generateRandomNumbers(); + final String _code = code ?? generateRandomNumbers(); - http.Response response = await http.post( + final http.Response response = await http.post( Uri.parse( '$baseURLOTP?username=$userName&password=$password&msignature=$otpSignature&token=$otpToken&sender=$senderName&mobile=$phoneNumber&code=$_code', ), ); if (response.statusCode == 200 && response.body.contains('"SMSID"')) { - print(response.body); return code; } else { developer.log( diff --git a/pubspec.yaml b/pubspec.yaml index 8a5ec95..f0a86e2 100644 --- a/pubspec.yaml +++ b/pubspec.yaml @@ -1,14 +1,15 @@ name: palestine_sms_misr description: Lightweight SMS Misr gateway implementation in dart (unofficial). -version: 0.0.6 +version: 0.0.7 homepage: https://github.com/msayed-net/PalestineDevelopers environment: - sdk: ">=2.15.1 <3.0.0" + sdk: ">=2.12.0 <3.0.0" dependencies: http: ^0.13.4 dev_dependencies: lint: ^1.0.0 + test: ^1.20.1 diff --git a/test/palestine_sms_misr_base_test.dart b/test/palestine_sms_misr_base_test.dart new file mode 100644 index 0000000..283f075 --- /dev/null +++ b/test/palestine_sms_misr_base_test.dart @@ -0,0 +1,38 @@ +import 'package:palestine_sms_misr/palestine_sms_misr.dart'; +import 'package:test/test.dart'; + +void main() { + final PalSMSMisr palSMSMisr = PalSMSMisr( + senderName: 'xxxx', + language: '2', + userName: 'user', + password: 'password', + otpToken: 'token12', + otpSignature: 'signature', + ); + + test('if can send message and OTP', () async { + expect( + await palSMSMisr.sendMessage( + phoneNumbers: '01004104004', + message: 'test message', + ), + isFalse, + ); + expect( + (await palSMSMisr.sendOTP( + phoneNumber: '01004104004', + code: '12012', + )) + .runtimeType, + anyOf([String, Null]), + ); + expect( + (await palSMSMisr.sendOTP( + phoneNumber: '01004104004', + )) + .runtimeType, + anyOf([String, Null]), + ); + }); +}