mod common;
use apollo_errors::Error as ErrorTrait;
use common::{ErrorWithFields, SimpleError};
use insta::assert_json_snapshot;
#[test]
fn test_simple_code_format() {
let error = SimpleError::Simple;
let json = error.to_json().unwrap();
assert_json_snapshot!(json, @r#"
{
"error": "errors::simple",
"message": "Something went wrong"
}
"#);
}
#[test]
fn test_nested_code_format() {
let error = ErrorWithFields::InvalidPort {
port: 8080,
config_file: String::new(),
};
let json = error.to_json().unwrap();
assert_json_snapshot!(json, @r#"
{
"config_file": "",
"error": "config::invalid_port",
"message": "Invalid port",
"port": 8080
}
"#);
}
#[test]
fn test_code_in_graphql_extensions() {
let error = SimpleError::Simple;
let graphql = error.to_graphql().unwrap();
assert_json_snapshot!(graphql, @r#"
{
"extensions": {
"code": "errors::simple"
},
"message": "Something went wrong"
}
"#);
}