From 35d84ac7ffa8b6168a36455757ef5f2cbdb6dd6c Mon Sep 17 00:00:00 2001 From: Pietro Bongiovanni Date: Mon, 11 Dec 2023 13:49:26 +0100 Subject: [PATCH] Try workflow to release mollie-sdk crate --- .github/workflows/release-api-crate.yml | 46 +++++++++++++++++++++++++ Cargo.lock | 2 +- crates/mollie_api/Cargo.toml | 2 +- crates/mollie_api/src/lib.rs | 18 ++++++++++ 4 files changed, 66 insertions(+), 2 deletions(-) create mode 100644 .github/workflows/release-api-crate.yml diff --git a/.github/workflows/release-api-crate.yml b/.github/workflows/release-api-crate.yml new file mode 100644 index 0000000..34388a7 --- /dev/null +++ b/.github/workflows/release-api-crate.yml @@ -0,0 +1,46 @@ +name: Rust Build and Release + +on: + push: + branches: + - main + paths: + - 'ctates/mollie_api/**' + release: + types: [created] + +jobs: + build_and_test: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v2 + - name: Install Rust + uses: actions-rs/toolchain@v1 + with: + profile: minimal + toolchain: stable + override: true + - name: Build + run: cargo build --verbose + - name: Run tests + run: cargo test --verbose + + release: + needs: build_and_test + runs-on: ubuntu-latest + if: github.event_name == 'release' && github.event.action == 'created' + steps: + - uses: actions/checkout@v2 + - name: Install Rust + uses: actions-rs/toolchain@v1 + with: + profile: minimal + toolchain: stable + override: true + - name: Change to SDK directory + run: cd sdk + - name: Publish to Crates.io + uses: actions-rs/cargo@v1 + with: + command: publish + args: --token ${{ secrets.CRATES_IO_TOKEN }} diff --git a/Cargo.lock b/Cargo.lock index a59d761..8c794eb 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -695,7 +695,7 @@ dependencies = [ [[package]] name = "mollie_api" -version = "0.1.0" +version = "0.0.1" dependencies = [ "chrono", "lazy_static", diff --git a/crates/mollie_api/Cargo.toml b/crates/mollie_api/Cargo.toml index 8515f96..1d12239 100644 --- a/crates/mollie_api/Cargo.toml +++ b/crates/mollie_api/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "mollie_api" -version = "0.1.0" +version = "0.0.1" edition.workspace = true homepage.workspace = true repository.workspace = true diff --git a/crates/mollie_api/src/lib.rs b/crates/mollie_api/src/lib.rs index fb4fe78..3236b5e 100644 --- a/crates/mollie_api/src/lib.rs +++ b/crates/mollie_api/src/lib.rs @@ -160,3 +160,21 @@ impl<'c> Mollie<'c> { organizations::OrganizationsApi::new(&self.api_client) } } + +#[cfg(test)] +mod client_tests { + use super::Mollie; + + #[tokio::test] + async fn test_organization_api_is_unauthorized() { + let auth_token = String::from("access_invalidAccessToken"); + let client = Mollie::build(&auth_token); + + match client.organizations().me().await { + Ok(_r) => panic!("Expected API to return a 401 error code, but got a valid response."), + Err(e) => { + assert!(e.to_string().contains("Mollie API Error 401: Unauthorized Request - Missing authentication, or failed to authenticate.")); + } + } + } +} \ No newline at end of file