Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 6 additions & 6 deletions test/local/tools.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ describe('registerTools', () => {
});

describe('create_project', () => {
it('should create a project with a provided id', async () => {
it('should return a simple success message when billing is attached', async () => {
const server = {
registerTool: mock.fn(),
};
Expand All @@ -73,8 +73,8 @@ describe('registerTools', () => {
'../../lib/gcp-projects.js': {
createProjectAndAttachBilling: (projectId) =>
Promise.resolve({
projectId: projectId,
billingMessage: 'billing message',
projectId: 'my-project',
billingMessage: 'Successfully attached billing.',
}),
},
});
Expand All @@ -96,7 +96,7 @@ describe('registerTools', () => {
});
});

it('should create a project with a generated id', async () => {
it('should return the full warning message when billing fails', async () => {
const server = {
registerTool: mock.fn(),
};
Expand All @@ -106,7 +106,7 @@ describe('registerTools', () => {
createProjectAndAttachBilling: () =>
Promise.resolve({
projectId: 'generated-project',
billingMessage: 'billing message',
billingMessage: 'Project created. No billing accounts found.',
}),
},
});
Expand All @@ -122,7 +122,7 @@ describe('registerTools', () => {
content: [
{
type: 'text',
text: 'Successfully created GCP project with ID "generated-project". You can now use this project ID for deployments.',
text: 'Project created. No billing accounts found.',
},
],
});
Expand Down
13 changes: 12 additions & 1 deletion test/need-gcp/gcp-projects.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,18 @@ async function main() {
`Successfully created project: ${newProjectResult.projectId}`
);
console.log(newProjectResult.billingMessage);
console.log('\nProject creation test completed successfully.');

if (newProjectResult.billingMessage.includes('No billing accounts found')) {
console.log(
'\nTest passed: Correctly received the billing warning message.'
);
process.exit(0);
} else {
console.error(
'\nTest failed: Did not receive the expected billing warning message.'
);
process.exit(1);
}
} else {
console.error(
'Failed to create a new project or retrieve project details.'
Expand Down
27 changes: 19 additions & 8 deletions tools.js
Original file line number Diff line number Diff line change
Expand Up @@ -123,14 +123,25 @@ export const registerTools = (
}
try {
const result = await createProjectAndAttachBilling(projectId);
return {
content: [
{
type: 'text',
text: `Successfully created GCP project with ID "${result.projectId}". You can now use this project ID for deployments.`,
},
],
};
if (result.billingMessage.includes('Successfully')) {
return {
content: [
{
type: 'text',
text: `Successfully created GCP project with ID "${result.projectId}". You can now use this project ID for deployments.`,
},
],
};
} else {
return {
content: [
{
type: 'text',
text: result.billingMessage,
},
],
};
}
} catch (error) {
return {
content: [
Expand Down