Skip to content

Commit

Permalink
add graphql tests
Browse files Browse the repository at this point in the history
  • Loading branch information
aumetra committed Mar 18, 2024
1 parent 99d4e6f commit c6ec4b1
Showing 1 changed file with 34 additions and 0 deletions.
34 changes: 34 additions & 0 deletions lib/speedy-uuid/tests/async_graphql.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
#![cfg(feature = "async-graphql")]

use async_graphql::{connection::CursorType, ScalarType};
use speedy_uuid::Uuid;

const UUID: &str = "38058daf-b2cd-4832-902a-83583ac07e28";
const UUID_BYTES: [u8; 16] = [
0x38, 0x05, 0x8d, 0xaf, 0xb2, 0xcd, 0x48, 0x32, 0x90, 0x2a, 0x83, 0x58, 0x3a, 0xc0, 0x7e, 0x28,
];

#[test]
fn cursor_encode_decode() {
let parsed_cursor: Uuid = CursorType::decode_cursor(UUID).unwrap();
assert_eq!(parsed_cursor.as_bytes(), &UUID_BYTES);

let result: Result<Uuid, speedy_uuid::Error> = CursorType::decode_cursor("NOT A UUID");
assert!(result.is_err());

let encoded_cursor = CursorType::encode_cursor(&parsed_cursor);
assert_eq!(encoded_cursor, UUID);
}

#[test]
fn scalar_encode_decode() {
let parsed_scalar: Uuid = ScalarType::parse(async_graphql::Value::String(UUID.into())).unwrap();
assert_eq!(parsed_scalar.as_bytes(), &UUID_BYTES);

let result: async_graphql::InputValueResult<Uuid> =
ScalarType::parse(async_graphql::Value::Null);
assert!(result.is_err());

let encoded_scalar = ScalarType::to_value(&parsed_scalar);
assert_eq!(encoded_scalar, async_graphql::Value::String(UUID.into()));
}

0 comments on commit c6ec4b1

Please sign in to comment.