We provide all the information about MCP servers via our MCP API.
curl -X GET 'https://glama.ai/api/mcp/v1/servers/kuro-tomo/shopify-agentic-mcp'
If you have feedback or need assistance with the MCP directory API, please join our Discord server
import { describe, it, expect } from 'vitest';
import { MandateStore } from '../../src/ap2/mandate-store.js';
import type { Mandate, CartPayload, PaymentPayload, IntentPayload } from '../../src/types.js';
// ─── Helpers ───
function makeCartMandate(overrides: Partial<Mandate> = {}): Mandate {
return {
id: 'mandate-cart-1',
type: 'cart',
status: 'active',
issuer: 'merchant-1',
subject: 'buyer@example.com',
payload: {
checkout_id: 'checkout-1',
line_items: [],
totals: {
subtotal: 1000,
tax: 80,
shipping: 0,
discount: 0,
fee: 5,
total: 1085,
currency: 'USD',
},
merchant_signature: 'sig-placeholder',
} as CartPayload,
signature: 'jws-placeholder',
issued_at: new Date().toISOString(),
expires_at: new Date(Date.now() + 30 * 60 * 1000).toISOString(), // 30 min future
...overrides,
};
}
function makePaymentMandate(checkoutId: string): Mandate {
return {
id: 'mandate-payment-1',
type: 'payment',
status: 'active',
issuer: 'merchant-1',
subject: 'buyer@example.com',
payload: {
checkout_id: checkoutId,
amount: 1085,
currency: 'USD',
payment_handler_id: 'shopify_payments',
cart_mandate_id: 'mandate-cart-1',
} as PaymentPayload,
signature: 'jws-placeholder',
issued_at: new Date().toISOString(),
expires_at: new Date(Date.now() + 30 * 60 * 1000).toISOString(),
};
}
function makeExpiredMandate(): Mandate {
return makeCartMandate({
id: 'mandate-expired',
expires_at: new Date(Date.now() - 60 * 1000).toISOString(), // 1 minute ago
});
}
// ─── store / get ───
describe('MandateStore — store and get', () => {
it('stores a mandate and retrieves it by id', async () => {
const store = new MandateStore();
const mandate = makeCartMandate();
await store.store(mandate);
const retrieved = await store.get(mandate.id);
expect(retrieved).not.toBeNull();
expect(retrieved!.id).toBe(mandate.id);
expect(retrieved!.type).toBe('cart');
expect(retrieved!.status).toBe('active');
});
it('returns null for a non-existent id', async () => {
const store = new MandateStore();
const result = await store.get('does-not-exist');
expect(result).toBeNull();
});
it('returns a copy, not the original reference', async () => {
const store = new MandateStore();
const mandate = makeCartMandate();
await store.store(mandate);
const a = await store.get(mandate.id);
const b = await store.get(mandate.id);
expect(a).not.toBe(b); // different references
expect(a).toEqual(b); // same data
});
});
// ─── getByCheckout ───
describe('MandateStore — getByCheckout', () => {
it('returns mandates indexed by checkout_id', async () => {
const store = new MandateStore();
const cartMandate = makeCartMandate();
const paymentMandate = makePaymentMandate('checkout-1');
await store.store(cartMandate);
await store.store(paymentMandate);
const results = await store.getByCheckout('checkout-1');
expect(results).toHaveLength(2);
const ids = results.map((m) => m.id);
expect(ids).toContain('mandate-cart-1');
expect(ids).toContain('mandate-payment-1');
});
it('returns empty array for non-existent checkout_id', async () => {
const store = new MandateStore();
const results = await store.getByCheckout('nonexistent');
expect(results).toHaveLength(0);
});
it('does not index intent mandates (no checkout_id)', async () => {
const store = new MandateStore();
const intentMandate: Mandate = {
id: 'mandate-intent-1',
type: 'intent',
status: 'active',
issuer: 'buyer-agent',
subject: 'buyer@example.com',
payload: {
max_amount: 50000,
currency: 'USD',
} as IntentPayload,
signature: 'jws-placeholder',
issued_at: new Date().toISOString(),
expires_at: new Date(Date.now() + 30 * 60 * 1000).toISOString(),
};
await store.store(intentMandate);
// Intent mandates have no checkout_id, so getByCheckout returns nothing
const results = await store.getByCheckout('checkout-1');
expect(results).toHaveLength(0);
});
});
// ─── revoke ───
describe('MandateStore — revoke', () => {
it('changes status to revoked', async () => {
const store = new MandateStore();
const mandate = makeCartMandate();
await store.store(mandate);
await store.revoke(mandate.id);
const retrieved = await store.get(mandate.id);
expect(retrieved!.status).toBe('revoked');
});
it('throws for non-existent mandate', async () => {
const store = new MandateStore();
await expect(store.revoke('does-not-exist')).rejects.toThrow('Mandate not found');
});
});
// ─── cleanup ───
describe('MandateStore — cleanup', () => {
it('removes expired mandates', async () => {
const store = new MandateStore();
const active = makeCartMandate();
const expired = makeExpiredMandate();
await store.store(active);
await store.store(expired);
const removed = await store.cleanup();
expect(removed).toBe(1);
// Active mandate still exists
const retrievedActive = await store.get(active.id);
expect(retrievedActive).not.toBeNull();
// Expired mandate is gone
const retrievedExpired = await store.get(expired.id);
expect(retrievedExpired).toBeNull();
});
it('returns 0 when there are no expired mandates', async () => {
const store = new MandateStore();
const active = makeCartMandate();
await store.store(active);
const removed = await store.cleanup();
expect(removed).toBe(0);
});
it('cleans up checkout index for removed mandates', async () => {
const store = new MandateStore();
const expired = makeExpiredMandate();
await store.store(expired);
// Before cleanup, should be indexed
const before = await store.getByCheckout('checkout-1');
expect(before).toHaveLength(1);
await store.cleanup();
// After cleanup, index should be empty
const after = await store.getByCheckout('checkout-1');
expect(after).toHaveLength(0);
});
});