Tests 3 restructure (#754)

* moved files

* moved files

* initial v3 additions

* moves req data

* tests passing, restructuring, remove v2

* fmt; clippy; prepare

* merge conflicts + issues

* merge conflict, fmt, clippy, prepare

* revs

* fixed failing test

* fixed tests
This commit is contained in:
Wyatt Verchere
2023-11-16 10:36:03 -08:00
committed by GitHub
parent f4880d0519
commit 74973e73e6
66 changed files with 4282 additions and 1033 deletions

View File

@@ -1,12 +1,10 @@
use actix_web::test;
use chrono::{Duration, Utc};
use common::database::*;
use common::environment::TestEnvironment;
use labrinth::models::pats::Scopes;
use serde_json::json;
use crate::common::environment::TestEnvironment;
// importing common module.
mod common;
// Full pat test:
@@ -22,7 +20,7 @@ pub async fn pat_full_test() {
// Create a PAT for a full test
let req = test::TestRequest::post()
.uri("/v2/pat")
.uri("/v3/pat")
.append_header(("Authorization", USER_USER_PAT))
.set_json(json!({
"scopes": Scopes::COLLECTION_CREATE, // Collection create as an easily tested example
@@ -46,7 +44,7 @@ pub async fn pat_full_test() {
// Get PAT again
let req = test::TestRequest::get()
.append_header(("Authorization", USER_USER_PAT))
.uri("/v2/pat")
.uri("/v3/pat")
.to_request();
let resp = test_env.call(req).await;
assert_eq!(resp.status().as_u16(), 200);
@@ -62,7 +60,7 @@ pub async fn pat_full_test() {
let token = token.to_string();
async {
let req = test::TestRequest::post()
.uri("/v2/collection")
.uri("/v3/collection")
.append_header(("Authorization", token))
.set_json(json!({
"title": "Test Collection 1",
@@ -78,7 +76,7 @@ pub async fn pat_full_test() {
// Change scopes and test again
let req = test::TestRequest::patch()
.uri(&format!("/v2/pat/{}", id))
.uri(&format!("/v3/pat/{}", id))
.append_header(("Authorization", USER_USER_PAT))
.set_json(json!({
"scopes": 0,
@@ -90,7 +88,7 @@ pub async fn pat_full_test() {
// Change scopes back, and set expiry to the past, and test again
let req = test::TestRequest::patch()
.uri(&format!("/v2/pat/{}", id))
.uri(&format!("/v3/pat/{}", id))
.append_header(("Authorization", USER_USER_PAT))
.set_json(json!({
"scopes": Scopes::COLLECTION_CREATE,
@@ -106,7 +104,7 @@ pub async fn pat_full_test() {
// Change everything back to normal and test again
let req = test::TestRequest::patch()
.uri(&format!("/v2/pat/{}", id))
.uri(&format!("/v3/pat/{}", id))
.append_header(("Authorization", USER_USER_PAT))
.set_json(json!({
"expires": Utc::now() + Duration::days(1), // no longer expired!
@@ -118,7 +116,7 @@ pub async fn pat_full_test() {
// Patching to a bad expiry should fail
let req = test::TestRequest::patch()
.uri(&format!("/v2/pat/{}", id))
.uri(&format!("/v3/pat/{}", id))
.append_header(("Authorization", USER_USER_PAT))
.set_json(json!({
"expires": Utc::now() - Duration::days(1), // Past
@@ -135,7 +133,7 @@ pub async fn pat_full_test() {
}
let req = test::TestRequest::patch()
.uri(&format!("/v2/pat/{}", id))
.uri(&format!("/v3/pat/{}", id))
.append_header(("Authorization", USER_USER_PAT))
.set_json(json!({
"scopes": scope.bits(),
@@ -151,7 +149,7 @@ pub async fn pat_full_test() {
// Delete PAT
let req = test::TestRequest::delete()
.append_header(("Authorization", USER_USER_PAT))
.uri(&format!("/v2/pat/{}", id))
.uri(&format!("/v3/pat/{}", id))
.to_request();
let resp = test_env.call(req).await;
assert_eq!(resp.status().as_u16(), 204);
@@ -167,7 +165,7 @@ pub async fn bad_pats() {
// Creating a PAT with no name should fail
let req = test::TestRequest::post()
.uri("/v2/pat")
.uri("/v3/pat")
.append_header(("Authorization", USER_USER_PAT))
.set_json(json!({
"scopes": Scopes::COLLECTION_CREATE, // Collection create as an easily tested example
@@ -180,7 +178,7 @@ pub async fn bad_pats() {
// Name too short or too long should fail
for name in ["n", "this_name_is_too_long".repeat(16).as_str()] {
let req = test::TestRequest::post()
.uri("/v2/pat")
.uri("/v3/pat")
.append_header(("Authorization", USER_USER_PAT))
.set_json(json!({
"name": name,
@@ -194,7 +192,7 @@ pub async fn bad_pats() {
// Creating a PAT with an expiry in the past should fail
let req = test::TestRequest::post()
.uri("/v2/pat")
.uri("/v3/pat")
.append_header(("Authorization", USER_USER_PAT))
.set_json(json!({
"scopes": Scopes::COLLECTION_CREATE, // Collection create as an easily tested example
@@ -212,7 +210,7 @@ pub async fn bad_pats() {
continue;
}
let req = test::TestRequest::post()
.uri("/v2/pat")
.uri("/v3/pat")
.append_header(("Authorization", USER_USER_PAT))
.set_json(json!({
"scopes": scope.bits(),
@@ -229,7 +227,7 @@ pub async fn bad_pats() {
// Create a 'good' PAT for patching
let req = test::TestRequest::post()
.uri("/v2/pat")
.uri("/v3/pat")
.append_header(("Authorization", USER_USER_PAT))
.set_json(json!({
"scopes": Scopes::COLLECTION_CREATE,
@@ -245,7 +243,7 @@ pub async fn bad_pats() {
// Patching to a bad name should fail
for name in ["n", "this_name_is_too_long".repeat(16).as_str()] {
let req = test::TestRequest::post()
.uri("/v2/pat")
.uri("/v3/pat")
.append_header(("Authorization", USER_USER_PAT))
.set_json(json!({
"name": name,
@@ -257,7 +255,7 @@ pub async fn bad_pats() {
// Patching to a bad expiry should fail
let req = test::TestRequest::patch()
.uri(&format!("/v2/pat/{}", id))
.uri(&format!("/v3/pat/{}", id))
.append_header(("Authorization", USER_USER_PAT))
.set_json(json!({
"expires": Utc::now() - Duration::days(1), // Past
@@ -274,7 +272,7 @@ pub async fn bad_pats() {
}
let req = test::TestRequest::patch()
.uri(&format!("/v2/pat/{}", id))
.uri(&format!("/v3/pat/{}", id))
.append_header(("Authorization", USER_USER_PAT))
.set_json(json!({
"scopes": scope.bits(),