mod common;
use apollo_errors::Error as ErrorTrait;
use common::{ErrorWithFields, SimpleError};
use insta::assert_json_snapshot;
#[test]
fn test_simple_error_graphql() {
let error = SimpleError::Simple;
let graphql = error.to_graphql().unwrap();
assert_json_snapshot!(graphql, @r#"
{
"extensions": {
"code": "errors::simple"
},
"message": "Something went wrong"
}
"#);
}
#[test]
fn test_another_error_graphql() {
let error = SimpleError::Another;
let graphql = error.to_graphql().unwrap();
assert_json_snapshot!(graphql, @r#"
{
"extensions": {
"code": "errors::another"
},
"message": "Another error occurred"
}
"#);
}
#[test]
fn test_error_with_fields_graphql() {
let error = ErrorWithFields::InvalidPort {
port: 8080,
config_file: "/etc/config.toml".to_string(),
};
let graphql = error.to_graphql().unwrap();
assert_json_snapshot!(graphql, @r#"
{
"extensions": {
"code": "config::invalid_port",
"config_file": "/etc/config.toml",
"port": 8080
},
"message": "Invalid port"
}
"#);
}
#[test]
fn test_error_with_single_field_graphql() {
let error = ErrorWithFields::MissingConfig {
expected_path: "/app/config.yaml".to_string(),
};
let graphql = error.to_graphql().unwrap();
assert_json_snapshot!(graphql, @r#"
{
"extensions": {
"code": "config::missing",
"expected_path": "/app/config.yaml"
},
"message": "Missing configuration"
}
"#);
}