Milestone 0: import zappier billing, Verae middleware, and Zapier research
Compose-ready workspace: packages/zappier (rate card, portal, Stripe), packages/verae-zapier-middleware (timestamp + NATS), packages/verae-zapier (CLI app), vendor/zapier-platform, and research/zapier vendor corpus. Gate 0 structure checks pass. Product code and research are not yet wired.
This commit is contained in:
commit
b4150c8250
1364 changed files with 6814366 additions and 0 deletions
66
vendor/zapier-platform/example-apps/openai/test/authentication.test.js
vendored
Normal file
66
vendor/zapier-platform/example-apps/openai/test/authentication.test.js
vendored
Normal file
|
|
@ -0,0 +1,66 @@
|
|||
/* globals describe, it, expect */
|
||||
/* eslint-disable no-undef */
|
||||
|
||||
const App = require('../index');
|
||||
|
||||
describe('custom auth', () => {
|
||||
beforeEach(() => {
|
||||
jest.clearAllMocks();
|
||||
});
|
||||
|
||||
it('passes authentication and returns json', async () => {
|
||||
const bundle = {
|
||||
authData: {
|
||||
api_key: 'secret',
|
||||
},
|
||||
};
|
||||
|
||||
// Mock successful response
|
||||
const mockResponse = {
|
||||
status: 200,
|
||||
data: {
|
||||
email: 'test@example.com',
|
||||
},
|
||||
};
|
||||
|
||||
// Mock the request client
|
||||
const mockRequest = jest.fn().mockResolvedValue(mockResponse);
|
||||
const z = {
|
||||
request: mockRequest,
|
||||
};
|
||||
|
||||
const response = await App.authentication.test(z, bundle);
|
||||
|
||||
expect(mockRequest).toHaveBeenCalledTimes(1);
|
||||
expect(mockRequest).toHaveBeenCalledWith({
|
||||
url: expect.stringContaining('/me'),
|
||||
});
|
||||
expect(response.status).toBe(200);
|
||||
expect(response.data).toHaveProperty('email', 'test@example.com');
|
||||
});
|
||||
|
||||
it('fails on bad auth', async () => {
|
||||
const bundle = {
|
||||
authData: {
|
||||
api_key: 'bad',
|
||||
},
|
||||
};
|
||||
|
||||
// Mock failed response
|
||||
const mockRequest = jest
|
||||
.fn()
|
||||
.mockRejectedValue(new Error('Incorrect API key provided'));
|
||||
const z = {
|
||||
request: mockRequest,
|
||||
};
|
||||
|
||||
try {
|
||||
await App.authentication.test(z, bundle);
|
||||
} catch (error) {
|
||||
expect(mockRequest).toHaveBeenCalledTimes(1);
|
||||
expect(error.message).toContain('Incorrect API key provided');
|
||||
return;
|
||||
}
|
||||
throw new Error('appTester should have thrown');
|
||||
});
|
||||
});
|
||||
150
vendor/zapier-platform/example-apps/openai/test/chat_completion.test.js
vendored
Normal file
150
vendor/zapier-platform/example-apps/openai/test/chat_completion.test.js
vendored
Normal file
|
|
@ -0,0 +1,150 @@
|
|||
/* globals describe, it, expect */
|
||||
/* eslint-disable no-undef */
|
||||
|
||||
const chatCompletion = require('../creates/chat_completion');
|
||||
const { DEFAULT_MODEL } = require('../constants');
|
||||
|
||||
describe('chat_completion', () => {
|
||||
beforeEach(() => {
|
||||
jest.clearAllMocks();
|
||||
});
|
||||
|
||||
it('creates a basic chat completion', async () => {
|
||||
const bundle = {
|
||||
inputData: {
|
||||
user_message: 'Hello, how are you?',
|
||||
model: DEFAULT_MODEL,
|
||||
},
|
||||
};
|
||||
|
||||
const mockResponse = {
|
||||
data: {
|
||||
id: 'chatcmpl-123',
|
||||
model: DEFAULT_MODEL,
|
||||
usage: {
|
||||
prompt_tokens: 20,
|
||||
completion_tokens: 15,
|
||||
total_tokens: 35,
|
||||
},
|
||||
choices: [
|
||||
{
|
||||
message: {
|
||||
content: 'I am doing well, thank you for asking!',
|
||||
},
|
||||
},
|
||||
],
|
||||
},
|
||||
};
|
||||
|
||||
const mockRequest = jest.fn().mockResolvedValue(mockResponse);
|
||||
const z = { request: mockRequest };
|
||||
|
||||
const result = await chatCompletion.operation.perform(z, bundle);
|
||||
|
||||
expect(mockRequest).toHaveBeenCalledTimes(1);
|
||||
expect(mockRequest).toHaveBeenCalledWith({
|
||||
url: expect.stringContaining('/chat/completions'),
|
||||
method: 'POST',
|
||||
body: expect.stringContaining(bundle.inputData.user_message),
|
||||
});
|
||||
|
||||
expect(result).toEqual(mockResponse.data);
|
||||
});
|
||||
|
||||
it('creates a chat completion with advanced options', async () => {
|
||||
const bundle = {
|
||||
inputData: {
|
||||
user_message: 'Write a story',
|
||||
model: DEFAULT_MODEL,
|
||||
developer_message: 'You are a creative writer',
|
||||
temperature: 0.9,
|
||||
max_completion_tokens: 100,
|
||||
},
|
||||
};
|
||||
|
||||
const mockResponse = {
|
||||
data: {
|
||||
id: 'chatcmpl-456',
|
||||
model: DEFAULT_MODEL,
|
||||
usage: {
|
||||
prompt_tokens: 25,
|
||||
completion_tokens: 50,
|
||||
total_tokens: 75,
|
||||
},
|
||||
},
|
||||
};
|
||||
|
||||
const mockRequest = jest.fn().mockResolvedValue(mockResponse);
|
||||
const z = { request: mockRequest };
|
||||
|
||||
const result = await chatCompletion.operation.perform(z, bundle);
|
||||
|
||||
expect(mockRequest).toHaveBeenCalledTimes(1);
|
||||
expect(mockRequest).toHaveBeenCalledWith({
|
||||
url: expect.stringContaining('/chat/completions'),
|
||||
method: 'POST',
|
||||
body: expect.stringMatching(/temperature.*0.9/),
|
||||
});
|
||||
|
||||
expect(result).toEqual(mockResponse.data);
|
||||
});
|
||||
|
||||
it('creates a chat completion with image', async () => {
|
||||
const bundle = {
|
||||
inputData: {
|
||||
user_message: 'Describe this image',
|
||||
model: DEFAULT_MODEL,
|
||||
files: ['https://example.com/image.jpg'],
|
||||
},
|
||||
};
|
||||
|
||||
const mockResponse = {
|
||||
data: {
|
||||
id: 'chatcmpl-789',
|
||||
model: DEFAULT_MODEL,
|
||||
usage: {
|
||||
prompt_tokens: 30,
|
||||
completion_tokens: 20,
|
||||
total_tokens: 50,
|
||||
},
|
||||
},
|
||||
};
|
||||
|
||||
const mockRequest = jest.fn().mockResolvedValue(mockResponse);
|
||||
const z = { request: mockRequest };
|
||||
|
||||
const result = await chatCompletion.operation.perform(z, bundle);
|
||||
|
||||
expect(mockRequest).toHaveBeenCalledTimes(1);
|
||||
expect(mockRequest).toHaveBeenCalledWith({
|
||||
url: expect.stringContaining('/chat/completions'),
|
||||
method: 'POST',
|
||||
body: expect.stringMatching(/image_url.*example.com/),
|
||||
});
|
||||
|
||||
expect(result).toEqual(mockResponse.data);
|
||||
});
|
||||
|
||||
it('handles API errors', async () => {
|
||||
const bundle = {
|
||||
inputData: {
|
||||
user_message: 'Hello',
|
||||
model: DEFAULT_MODEL,
|
||||
},
|
||||
};
|
||||
|
||||
const mockRequest = jest
|
||||
.fn()
|
||||
.mockRejectedValue(new Error('Invalid request'));
|
||||
const z = { request: mockRequest };
|
||||
|
||||
try {
|
||||
await chatCompletion.operation.perform(z, bundle);
|
||||
} catch (error) {
|
||||
expect(mockRequest).toHaveBeenCalledTimes(1);
|
||||
expect(error.message).toContain('Invalid request');
|
||||
return;
|
||||
}
|
||||
throw new Error('Should have thrown an error');
|
||||
});
|
||||
});
|
||||
51
vendor/zapier-platform/example-apps/openai/test/list_models.test.js
vendored
Normal file
51
vendor/zapier-platform/example-apps/openai/test/list_models.test.js
vendored
Normal file
|
|
@ -0,0 +1,51 @@
|
|||
/* globals describe, it, expect */
|
||||
/* eslint-disable no-undef */
|
||||
|
||||
const listModels = require('../dynamic_dropdowns/list_models');
|
||||
|
||||
describe('list_models', () => {
|
||||
beforeEach(() => {
|
||||
jest.clearAllMocks();
|
||||
});
|
||||
|
||||
it('returns formatted list of models', async () => {
|
||||
const mockResponse = {
|
||||
data: {
|
||||
data: [{ id: 'gpt-4' }, { id: 'gpt-3.5-turbo' }],
|
||||
},
|
||||
};
|
||||
|
||||
const mockRequest = jest.fn().mockResolvedValue(mockResponse);
|
||||
const z = { request: mockRequest };
|
||||
const bundle = {};
|
||||
|
||||
const results = await listModels.operation.perform(z, bundle);
|
||||
|
||||
expect(mockRequest).toHaveBeenCalledTimes(1);
|
||||
expect(mockRequest).toHaveBeenCalledWith({
|
||||
url: expect.stringContaining('/models'),
|
||||
});
|
||||
|
||||
expect(results).toEqual([
|
||||
{ id: 'gpt-4', name: 'gpt-4' },
|
||||
{ id: 'gpt-3.5-turbo', name: 'gpt-3.5-turbo' },
|
||||
]);
|
||||
});
|
||||
|
||||
it('handles API errors', async () => {
|
||||
const mockRequest = jest
|
||||
.fn()
|
||||
.mockRejectedValue(new Error('Failed to fetch models'));
|
||||
const z = { request: mockRequest };
|
||||
const bundle = {};
|
||||
|
||||
try {
|
||||
await listModels.operation.perform(z, bundle);
|
||||
} catch (error) {
|
||||
expect(mockRequest).toHaveBeenCalledTimes(1);
|
||||
expect(error.message).toContain('Failed to fetch models');
|
||||
return;
|
||||
}
|
||||
throw new Error('Should have thrown an error');
|
||||
});
|
||||
});
|
||||
Loading…
Add table
Add a link
Reference in a new issue