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

refactor: tests #40

Merged
merged 5 commits into from
Mar 17, 2024
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
118 changes: 59 additions & 59 deletions .github/workflows/nightly.yml
Original file line number Diff line number Diff line change
Expand Up @@ -118,66 +118,66 @@ jobs:
command: make
args: docs_lint

build-docs:
name: build docs
runs-on: ubuntu-latest
steps:
- uses: pnpm/action-setup@v2
with:
version: 8
build-docs:
name: build docs
runs-on: ubuntu-latest
steps:
- uses: pnpm/action-setup@v2
with:
version: 8

- name: Install toolchain
uses: actions-rs/toolchain@v1
with:
toolchain: nightly
override: true

- name: Checkout Sources
uses: actions/checkout@v3

- name: Setup cache
uses: Swatinem/rust-cache@v2

- name: Install cargo-make
uses: actions-rs/cargo@v1
with:
command: install
- name: Install toolchain
uses: actions-rs/toolchain@v1
with:
toolchain: nightly
override: true

- name: Checkout Sources
uses: actions/checkout@v3

- name: Setup cache
uses: Swatinem/rust-cache@v2

- name: Install cargo-make
uses: actions-rs/cargo@v1
with:
command: install
args: cargo-make

- name: Build docs
uses: actions-rs/cargo@v1
with:
command: make
args: docs_build

- name: Archive artifact
run: |
tar \
--dereference --hard-dereference \
-cvf "$RUNNER_TEMP/pages.tar" \
docs/

- name: Upload artifact
id: upload-artifact
uses: actions/upload-artifact@v4
with:
name: pages
path: ${{ runner.temp }}/pages.tar
retention-days: 1
if-no-files-found: error
- name: Build docs
uses: actions-rs/cargo@v1
with:
command: make
args: docs_build

- name: Archive artifact
run: |
tar \
--dereference --hard-dereference \
-cvf "$RUNNER_TEMP/pages.tar" \
docs/

- name: Upload artifact
id: upload-artifact
uses: actions/upload-artifact@v4
with:
name: pages
path: ${{ runner.temp }}/pages.tar
retention-days: 1
if-no-files-found: error

deploy-docs:
needs: [build-docs]
runs-on: ubuntu-latest
permissions:
pages: write
id-token: write
environment:
name: github-pages
url: ${{ steps.deployment.outputs.page_url }}/nightly
steps:
- name: Deploy to pages
id: deployment
uses: actions/deploy-pages@v4
with:
artifact_name: "pages"
deploy-docs:
needs: [build-docs]
runs-on: ubuntu-latest
permissions:
pages: write
id-token: write
environment:
name: github-pages
url: ${{ steps.deployment.outputs.page_url }}/nightly
steps:
- name: Deploy to pages
id: deployment
uses: actions/deploy-pages@v4
with:
artifact_name: "pages"
31 changes: 29 additions & 2 deletions Makefile.toml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ skip_core_tasks = true
command = "pnpm"
args = ["i"]

# Development
# openapi docs

[tasks.docs_generate]
dependencies = ["docs_init"]
Expand All @@ -19,6 +19,27 @@ dependencies = ["docs_generate"]
command = "npx"
args = ["redocly", "preview-docs", "target/openapi.yaml"]

# lib dev

[tasks.core_build]
cwd = "./lib/core/"
command = "pnpm"
args = ["run", "tsc"]

[tasks.vue]
dependencies = ["core_build"]
cwd = "./lib/vue/"
command = "pnpm"
args = ["run", "docs:dev"]

[tasks.vue_build]
dependencies = ["core_build"]
cwd = "./lib/vue/"
command = "pnpm"
args = ["run", "build"]

# linting

[tasks.check]
command = "cargo"
args = ["check", "--bin", "main"]
Expand All @@ -36,8 +57,10 @@ args = [
"warnings",
]

# run oidc server for integration tests

[tasks.oidc-server-mock]
script = "docker compose -f testing/oidc-mock/docker-compose.yaml up -d"
script = "docker compose -f tests/_common/oidc-mock/docker-compose.yaml up -d"

# Postgres
[tasks.postgres_database]
Expand Down Expand Up @@ -66,6 +89,8 @@ run_task = { name = [
[tasks.postgres_cleanup]
script = "docker kill postgres;docker rm postgres;docker kill oidc-server-mock;docker rm oidc-server-mock"

# run all tests

[tasks.test]
run_task = { name = ["postgres"] }

Expand All @@ -87,6 +112,8 @@ dependencies = ["docs_lint"]
command = "npx"
args = ["redocly", "build-docs", "target/openapi.yaml", "-o", "docs/rest/index.html"]

# bindings

[tasks.generate_bindings]
command = "cargo"
args = [
Expand Down
6 changes: 5 additions & 1 deletion src/routes/v1/prompt.rs
Original file line number Diff line number Diff line change
Expand Up @@ -43,10 +43,14 @@ pub async fn router(state: FeedbackFusionState) -> Router<FeedbackFusionState> {
pub struct CreateFeedbackPromptRequest {
#[validate(length(max = 255))]
title: String,
#[serde(default)]
#[serde(default = "bool_true")]
active: bool,
}

fn bool_true() -> bool {
true
}

/// POST /v1/target/:target/prompt
#[utoipa::path(post, path = "/v1/target/:target/prompt", request_body = CreateFeedbackPromptRequest, responses(
(status = 201, body = FeedbackPrompt)
Expand Down
2 changes: 1 addition & 1 deletion tests/common.rs
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ pub fn run_server() -> BackendServer {
let mut path = std::env::current_exe().unwrap();
assert!(path.pop());
assert!(path.pop());
path = path.join(env!("CARGO_PKG_NAME"));
path = path.join("main");

// prepare the command
let mut command = Command::new(path);
Expand Down
44 changes: 42 additions & 2 deletions tests/http_tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
//OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

use common::*;
use rbatis::sql::Page;

Check warning on line 24 in tests/http_tests.rs

View workflow job for this annotation

GitHub Actions / tests

use of deprecated struct `rbatis::sql::Page`: please use `rbatis::plugin::page::Page`
use reqwest::StatusCode;
use serde::Deserialize;
use test_log::test;
Expand Down Expand Up @@ -126,8 +126,8 @@
.unwrap();
assert_eq!(StatusCode::OK, response.status());

let data = response.json::<Page<TargetResponse>>().await.unwrap();

Check warning on line 129 in tests/http_tests.rs

View workflow job for this annotation

GitHub Actions / tests

use of deprecated struct `rbatis::sql::Page`: please use `rbatis::plugin::page::Page`
assert_eq!(1, data.records.len());

Check warning on line 130 in tests/http_tests.rs

View workflow job for this annotation

GitHub Actions / tests

use of deprecated field `rbatis::sql::Page::records`: please use `rbatis::plugin::page::Page`
let first = data.records.first().unwrap();
assert_eq!(&target, first);
}
Expand Down Expand Up @@ -246,7 +246,7 @@
.unwrap();
assert_eq!(StatusCode::OK, response.status());

let data = response.json::<Page<PromptResponse>>().await.unwrap();

Check warning on line 249 in tests/http_tests.rs

View workflow job for this annotation

GitHub Actions / tests

use of deprecated struct `rbatis::sql::Page`: please use `rbatis::plugin::page::Page`
assert_eq!(1, data.records.len());
assert_eq!(&prompt, data.records.first().unwrap());
}
Expand Down Expand Up @@ -300,7 +300,7 @@
assert_eq!(
false,
response
.json::<Page<PromptResponse>>()

Check warning on line 303 in tests/http_tests.rs

View workflow job for this annotation

GitHub Actions / tests

use of deprecated struct `rbatis::sql::Page`: please use `rbatis::plugin::page::Page`
.await
.unwrap()
.records
Expand Down Expand Up @@ -330,7 +330,7 @@
assert_eq!(
0,
response
.json::<Page<PromptResponse>>()

Check warning on line 333 in tests/http_tests.rs

View workflow job for this annotation

GitHub Actions / tests

use of deprecated struct `rbatis::sql::Page`: please use `rbatis::plugin::page::Page`
.await
.unwrap()
.records
Expand All @@ -345,7 +345,7 @@
let client = client().await;

// prepare dependencies
let (target, prompt) = {
let (target, prompt, inactive_prompt) = {
let target = {
let response = client
.post(format!("{}/v1/target", HTTP_ENDPOINT))
Expand All @@ -370,7 +370,20 @@
response.json::<PromptResponse>().await.unwrap()
};

(target, prompt)
let inactive_prompt = {
let response = client
.post(format!("{}/v1/target/{}/prompt", HTTP_ENDPOINT, &target.id))
.json(&serde_json::json!({
"title": "title",
"active": false
}))
.send()
.await
.unwrap();
response.json::<PromptResponse>().await.unwrap()
};

(target, prompt, inactive_prompt)
};

// test auth
Expand Down Expand Up @@ -470,11 +483,38 @@
.unwrap();
assert_eq!(StatusCode::OK, response.status());

let data = response.json::<Page<FieldResponse>>().await.unwrap();

Check warning on line 486 in tests/http_tests.rs

View workflow job for this annotation

GitHub Actions / tests

use of deprecated struct `rbatis::sql::Page`: please use `rbatis::plugin::page::Page`
assert_eq!(1, data.total);
assert_eq!(&&field, data.records.first().as_ref().unwrap());
}

// test fetch
{
let response = client
.get(format!(
"{}/v1/target/{}/prompt/{}/fetch",
HTTP_ENDPOINT, &target.id, &prompt.id
))
.send()
.await
.unwrap();
assert_eq!(StatusCode::OK, response.status());

let data = response.json::<Page<FieldResponse>>().await.unwrap();

Check warning on line 503 in tests/http_tests.rs

View workflow job for this annotation

GitHub Actions / tests

use of deprecated struct `rbatis::sql::Page`: please use `rbatis::plugin::page::Page`
assert_eq!(1, data.total);
assert_eq!(&&field, data.records.first().as_ref().unwrap());

let response = client
.get(format!(
"{}/v1/target/{}/prompt/{}/fetch",
HTTP_ENDPOINT, &target.id, &inactive_prompt.id
))
.send()
.await
.unwrap();
assert_eq!(StatusCode::FORBIDDEN, response.status());
}

// test put
{
// test put invalid options
Expand Down Expand Up @@ -511,7 +551,7 @@
.send()
.await
.unwrap();
let data = response.json::<Page<FieldResponse>>().await.unwrap();

Check warning on line 554 in tests/http_tests.rs

View workflow job for this annotation

GitHub Actions / tests

use of deprecated struct `rbatis::sql::Page`: please use `rbatis::plugin::page::Page`
assert_eq!("Updated", data.records.first().unwrap().title.as_str());
}

Expand All @@ -535,7 +575,7 @@
.send()
.await
.unwrap();
let page = response.json::<Page<FieldResponse>>().await.unwrap();

Check warning on line 578 in tests/http_tests.rs

View workflow job for this annotation

GitHub Actions / tests

use of deprecated struct `rbatis::sql::Page`: please use `rbatis::plugin::page::Page`
assert_eq!(0, page.total);
}
}
Expand Down
Loading