Skip to content

Commit

Permalink
add a small test for the id
Browse files Browse the repository at this point in the history
  • Loading branch information
armandobelardo committed Apr 15, 2024
1 parent 822b6dc commit be93837
Show file tree
Hide file tree
Showing 2 changed files with 41 additions and 5 deletions.
40 changes: 35 additions & 5 deletions servers/fdr/src/__test__/db/db.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -422,6 +422,31 @@ it("snippets dao", async () => {
},
},
});
await serverApp?.dao.snippets().storeSnippets({
storeSnippetsInfo: {
orgId: "acme",
apiId: "api",
sdk: {
type: "python",
sdk: {
package: "acme",
version: "0.0.2",
},
snippets: [
{
endpoint: {
path: "/users/v1",
method: FdrAPI.EndpointMethod.Get,
},
snippet: {
async_client: "client = AsyncAcme(api_key='YOUR_API_KEY')",
sync_client: "client = Acme(api_key='YOUR_API_KEY')",
},
},
],
},
},
});
// get snippets
const response = await serverApp?.dao.snippets().loadSnippetsPage({
loadSnippetsInfo: {
Expand Down Expand Up @@ -456,22 +481,27 @@ it("snippets dao", async () => {
throw new Error("expected a python snippet");
}
expect(snippet.sdk.package).toEqual("acme");
expect(snippet.sdk.version).toEqual("0.0.1");
expect(snippet.sdk.version).toEqual("0.0.2");
expect(snippet.async_client).toEqual("client = AsyncAcme(api_key='YOUR_API_KEY')");
expect(snippet.sync_client).toEqual("client = Acme(api_key='YOUR_API_KEY')");

const sdkId = await serverApp?.dao.sdks().getLatestSdkIdForPackage({ sdkPackage: "acme", language: "PYTHON" });
expect(sdkId).toEqual("python|acme|0.0.1");
const sdkId = await serverApp?.dao.sdks().getSdkIdForPackage({ sdkPackage: "acme", language: "PYTHON" });
expect(sdkId).toEqual("python|acme|0.0.2");

const sdkIdPrevious = await serverApp?.dao
.sdks()
.getSdkIdForPackage({ sdkPackage: "acme", language: "PYTHON", version: "0.0.1" });
expect(sdkIdPrevious).toEqual("python|acme|0.0.2");

const snippetsForSdkId = await serverApp?.dao.snippets().loadAllSnippetsForSdkIds(sdkId != null ? [sdkId] : []);
expect(snippetsForSdkId).toEqual({
"python|acme|0.0.1": {
"python|acme|0.0.2": {
"/users/v1": {
DELETE: [],
GET: [
{
async_client: "client = AsyncAcme(api_key='YOUR_API_KEY')",
sdk: { package: "acme", version: "0.0.1" },
sdk: { package: "acme", version: "0.0.2" },
sync_client: "client = Acme(api_key='YOUR_API_KEY')",
type: "python",
},
Expand Down
6 changes: 6 additions & 0 deletions servers/fdr/src/db/sdk/SdkDao.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,11 @@ export interface SdkDao {
getSdkIdForPackage({
sdkPackage,
language,
version,
}: {
sdkPackage: string;
language: Language;
version?: string;
}): Promise<SdkId | undefined>;
}

Expand All @@ -32,6 +34,7 @@ export class SdkDaoImpl implements SdkDao {
const sdkId = await this.getSdkIdForPackage({
sdkPackage: snippetConfig.typescriptSdk.package,
language: Language.TYPESCRIPT,
version: snippetConfig.typescriptSdk.version,
});
if (sdkId != null) {
result.typescriptSdk = { ...snippetConfig.typescriptSdk, sdkId };
Expand All @@ -41,6 +44,7 @@ export class SdkDaoImpl implements SdkDao {
const sdkId = await this.getSdkIdForPackage({
sdkPackage: snippetConfig.pythonSdk.package,
language: Language.PYTHON,
version: snippetConfig.pythonSdk.version,
});
if (sdkId != null) {
result.pythonSdk = { ...snippetConfig.pythonSdk, sdkId };
Expand All @@ -50,6 +54,7 @@ export class SdkDaoImpl implements SdkDao {
const sdkId = await this.getSdkIdForPackage({
sdkPackage: snippetConfig.javaSdk.coordinate,
language: Language.JAVA,
version: snippetConfig.javaSdk.version,
});
if (sdkId != null) {
result.javaSdk = { ...snippetConfig.javaSdk, sdkId };
Expand All @@ -59,6 +64,7 @@ export class SdkDaoImpl implements SdkDao {
const sdkId = await this.getSdkIdForPackage({
sdkPackage: snippetConfig.goSdk.githubRepo,
language: Language.GO,
version: snippetConfig.goSdk.version,
});
if (sdkId != null) {
result.goSdk = { ...snippetConfig.goSdk, sdkId };
Expand Down

0 comments on commit be93837

Please sign in to comment.