meld-spec
Version:
Specification for the Meld scripting language
149 lines (148 loc) • 5.14 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.apiTests = void 0;
/**
* Test cases for the @api directive that all implementations must pass
*/
exports.apiTests = [
// Minimal API configuration
{
name: 'minimal-api',
input: '@api github = {{ baseUrl: "https://api.github.com" }}',
expected: {
type: 'Directive',
directive: {
kind: 'api',
identifier: 'github',
config: {
baseUrl: 'https://api.github.com'
}
}
},
description: 'Minimal API with only baseUrl'
},
// Full API configuration
{
name: 'full-api',
input: '@api github = {{\n baseUrl: "https://api.github.com",\n headers: {\n Authorization: "Bearer ${ENV_TOKEN}",\n Accept: "application/json"\n },\n timeout: 5000,\n retries: 3\n }}',
expected: {
type: 'Directive',
directive: {
kind: 'api',
identifier: 'github',
config: {
baseUrl: 'https://api.github.com',
headers: {
Authorization: 'Bearer ${ENV_TOKEN}',
Accept: 'application/json'
},
timeout: 5000,
retries: 3
}
}
},
description: 'Full API configuration with all optional fields'
},
// Basic endpoint definition
{
name: 'basic-endpoint',
input: '@api github.issues = {{\n path: "/repos/${owner}/${repo}/issues"\n }}',
expected: {
type: 'Directive',
directive: {
kind: 'api',
identifier: 'github.issues',
endpoint: {
path: '/repos/${owner}/${repo}/issues'
}
}
},
description: 'Basic endpoint definition with path'
},
// Endpoint with methods
{
name: 'endpoint-with-methods',
input: '@api github.issues = {{\n path: "/repos/${owner}/${repo}/issues",\n methods: ["GET", "POST"]\n }}',
expected: {
type: 'Directive',
directive: {
kind: 'api',
identifier: 'github.issues',
endpoint: {
path: '/repos/${owner}/${repo}/issues',
methods: ['GET', 'POST']
}
}
},
description: 'Endpoint with allowed methods'
},
// Endpoint with path parameters
{
name: 'endpoint-with-params',
input: '@api github.issue = {{\n path: "/repos/${owner}/${repo}/issues/${number}",\n methods: ["GET", "PATCH", "DELETE"]\n }}',
expected: {
type: 'Directive',
directive: {
kind: 'api',
identifier: 'github.issue',
endpoint: {
path: '/repos/${owner}/${repo}/issues/${number}',
methods: ['GET', 'PATCH', 'DELETE']
}
}
},
description: 'Endpoint with path parameters'
},
// API with data variables
{
name: 'api-with-data',
input: '@api github = {{\n baseUrl: "https://api.github.com",\n headers: "#{headers}",\n timeout: "#{config.timeout}"\n }}',
expected: {
type: 'Directive',
directive: {
kind: 'api',
identifier: 'github',
config: {
baseUrl: 'https://api.github.com',
headers: '#{headers}',
timeout: '#{config.timeout}'
}
}
},
description: 'API configuration with data variables'
},
// Endpoint with query parameters
{
name: 'endpoint-with-query',
input: '@api github.search = {{\n path: "/search/repositories?q=${query}&sort=${sort}",\n methods: ["GET"]\n }}',
expected: {
type: 'Directive',
directive: {
kind: 'api',
identifier: 'github.search',
endpoint: {
path: '/search/repositories?q=${query}&sort=${sort}',
methods: ['GET']
}
}
},
description: 'Endpoint with query parameters'
},
// Nested endpoint paths
{
name: 'nested-endpoint',
input: '@api github.repos.issues = {{\n path: "/repos/${owner}/${repo}/issues",\n methods: ["GET", "POST"]\n }}',
expected: {
type: 'Directive',
directive: {
kind: 'api',
identifier: 'github.repos.issues',
endpoint: {
path: '/repos/${owner}/${repo}/issues',
methods: ['GET', 'POST']
}
}
},
description: 'Deeply nested endpoint definition'
}
];