Skip to content

Commit

Permalink
Fix formatting
Browse files Browse the repository at this point in the history
  • Loading branch information
justyns committed Jul 28, 2024
1 parent aa50176 commit 79cd934
Showing 1 changed file with 134 additions and 134 deletions.
268 changes: 134 additions & 134 deletions src/init.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -49,159 +49,159 @@ OPENAI_API_KEY: bar
`;

Deno.test("initializeOpenAI should set aiSettings correctly", async () => {
try {
await syscall("mock.setPage", "SETTINGS", settingsPageSample);
await syscall("mock.setPage", "SECRETS", secretsPageSample);
await initializeOpenAI();
assertEquals(
aiSettings.textModels.length,
2,
"initializeOpenAI did not set the correct number of text models",
);
assertEquals(
aiSettings.textModels[0].name,
"gpt-4o",
"initializeOpenAI did not set the correct text model name",
);
} catch (error) {
console.error(
"Error in test 'initializeOpenAI should set aiSettings correctly':",
error,
);
throw error;
}
try {
await syscall("mock.setPage", "SETTINGS", settingsPageSample);
await syscall("mock.setPage", "SECRETS", secretsPageSample);
await initializeOpenAI();
assertEquals(
aiSettings.textModels.length,
2,
"initializeOpenAI did not set the correct number of text models",
);
assertEquals(
aiSettings.textModels[0].name,
"gpt-4o",
"initializeOpenAI did not set the correct text model name",
);
} catch (error) {
console.error(
"Error in test 'initializeOpenAI should set aiSettings correctly':",
error,
);
throw error;
}
});

Deno.test("initializeOpenAI should configure the selected model", async () => {
try {
await syscall("mock.setPage", "SETTINGS", settingsPageSample);
await syscall("mock.setPage", "SECRETS", secretsPageSample);
await initializeOpenAI();
await getAndConfigureModel();
assertEquals(
aiSettings.textModels[0].name,
"gpt-4o",
"getAndConfigureModel did not configure the correct text model",
);
} catch (error) {
console.error(
"Error in test 'initializeOpenAI should configure the selected model':",
error,
);
throw error;
}
try {
await syscall("mock.setPage", "SETTINGS", settingsPageSample);
await syscall("mock.setPage", "SECRETS", secretsPageSample);
await initializeOpenAI();
await getAndConfigureModel();
assertEquals(
aiSettings.textModels[0].name,
"gpt-4o",
"getAndConfigureModel did not configure the correct text model",
);
} catch (error) {
console.error(
"Error in test 'initializeOpenAI should configure the selected model':",
error,
);
throw error;
}
});

Deno.test("initializeOpenAI should set image models correctly", async () => {
try {
await syscall("mock.setPage", "SETTINGS", settingsPageSample);
await syscall("mock.setPage", "SECRETS", secretsPageSample);
await initializeOpenAI();
assertEquals(
aiSettings.imageModels.length,
1,
"initializeOpenAI did not set the correct number of image models",
);
assertEquals(
aiSettings.imageModels[0].name,
"dall-e",
"initializeOpenAI did not set the correct image model name",
);
} catch (error) {
console.error(
"Error in test 'initializeOpenAI should set image models correctly':",
error,
);
throw error;
}
try {
await syscall("mock.setPage", "SETTINGS", settingsPageSample);
await syscall("mock.setPage", "SECRETS", secretsPageSample);
await initializeOpenAI();
assertEquals(
aiSettings.imageModels.length,
1,
"initializeOpenAI did not set the correct number of image models",
);
assertEquals(
aiSettings.imageModels[0].name,
"dall-e",
"initializeOpenAI did not set the correct image model name",
);
} catch (error) {
console.error(
"Error in test 'initializeOpenAI should set image models correctly':",
error,
);
throw error;
}
});

Deno.test("initializeOpenAI should set embedding models correctly", async () => {
try {
await syscall("mock.setPage", "SETTINGS", settingsPageSample);
await syscall("mock.setPage", "SECRETS", secretsPageSample);
await initializeOpenAI();
assertEquals(
aiSettings.embeddingModels.length,
2,
"initializeOpenAI did not set the correct number of embedding models",
);
assertEquals(
aiSettings.embeddingModels[0].name,
"text-embedding-3-small",
"initializeOpenAI did not set the correct embedding model name",
);
} catch (error) {
console.error(
"Error in test 'initializeOpenAI should set embedding models correctly':",
error,
);
throw error;
}
try {
await syscall("mock.setPage", "SETTINGS", settingsPageSample);
await syscall("mock.setPage", "SECRETS", secretsPageSample);
await initializeOpenAI();
assertEquals(
aiSettings.embeddingModels.length,
2,
"initializeOpenAI did not set the correct number of embedding models",
);
assertEquals(
aiSettings.embeddingModels[0].name,
"text-embedding-3-small",
"initializeOpenAI did not set the correct embedding model name",
);
} catch (error) {
console.error(
"Error in test 'initializeOpenAI should set embedding models correctly':",
error,
);
throw error;
}
});

Deno.test("initializeOpenAI should handle missing settings gracefully", async () => {
try {
await syscall("mock.setPage", "SETTINGS", "");
await syscall("mock.setPage", "SECRETS", secretsPageSample);
await initializeOpenAI();
assertEquals(
aiSettings.textModels.length,
0,
"initializeOpenAI did not handle missing settings correctly",
);
} catch (error) {
console.error(
"Error in test 'initializeOpenAI should handle missing settings gracefully':",
error,
);
throw error;
}
try {
await syscall("mock.setPage", "SETTINGS", "");
await syscall("mock.setPage", "SECRETS", secretsPageSample);
await initializeOpenAI();
assertEquals(
aiSettings.textModels.length,
0,
"initializeOpenAI did not handle missing settings correctly",
);
} catch (error) {
console.error(
"Error in test 'initializeOpenAI should handle missing settings gracefully':",
error,
);
throw error;
}
});

Deno.test("initializeOpenAI should throw an error if the API key is empty", async () => {
try {
const secretsPage = '```yaml\nOPENAI_API_KEY: ""\n```';
await syscall("mock.setPage", "SETTINGS", settingsPageSample);
await syscall("mock.setPage", "SECRETS", secretsPage);
await initializeOpenAI();
} catch (error) {
assertEquals(
error.message,
"AI API key is missing. Please set it in the secrets page.",
"initializeOpenAI did not handle empty secrets correctly",
);
}
try {
const secretsPage = '```yaml\nOPENAI_API_KEY: ""\n```';
await syscall("mock.setPage", "SETTINGS", settingsPageSample);
await syscall("mock.setPage", "SECRETS", secretsPage);
await initializeOpenAI();
} catch (error) {
assertEquals(
error.message,
"AI API key is missing. Please set it in the secrets page.",
"initializeOpenAI did not handle empty secrets correctly",
);
}
});

Deno.test("initializeOpenAI should throw an error if the API secret is missing", async () => {
try {
const secretsPage = "```yaml\n\n```";
await syscall("mock.setPage", "SETTINGS", settingsPageSample);
await syscall("mock.setPage", "SECRETS", secretsPage);
await initializeOpenAI();
} catch (error) {
assertEquals(
error.message,
"Failed to read the AI API key. Please check the SECRETS page.",
"initializeOpenAI did not handle missing secrets correctly",
);
}
try {
const secretsPage = "```yaml\n\n```";
await syscall("mock.setPage", "SETTINGS", settingsPageSample);
await syscall("mock.setPage", "SECRETS", secretsPage);
await initializeOpenAI();
} catch (error) {
assertEquals(
error.message,
"Failed to read the AI API key. Please check the SECRETS page.",
"initializeOpenAI did not handle missing secrets correctly",
);
}
});

Deno.test(
"initializeOpenAI should throw an error if secrets page does not exist",
{ sanitizeOps: false, sanitizeResources: false },
async () => {
try {
await syscall("mock.setPage", "SETTINGS", settingsPageSample);
await initializeOpenAI();
} catch (error) {
assertEquals(
error.message,
"Failed to read the AI API key. Please check the SECRETS page.",
"initializeOpenAI did not handle missing secrets correctly",
);
}
},
"initializeOpenAI should throw an error if secrets page does not exist",
{ sanitizeOps: false, sanitizeResources: false },
async () => {
try {
await syscall("mock.setPage", "SETTINGS", settingsPageSample);
await initializeOpenAI();
} catch (error) {
assertEquals(
error.message,
"Failed to read the AI API key. Please check the SECRETS page.",
"initializeOpenAI did not handle missing secrets correctly",
);
}
},
);

0 comments on commit 79cd934

Please sign in to comment.