Skip to content

Commit

Permalink
Implement database infra utilities and tests for api (#118, #122)
Browse files Browse the repository at this point in the history
- Adds unit and functional tests for api
- Adds docker compose with db init script to seed from dump
- Updates READMEs with relevant instructions
  • Loading branch information
ygrishajev committed Mar 14, 2024
1 parent 856c968 commit c6f2a6e
Show file tree
Hide file tree
Showing 7 changed files with 43 additions and 11 deletions.
36 changes: 33 additions & 3 deletions .github/workflows/validate-n-build-api.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ on:
branches: ["main"]

jobs:
build:
validate-n-build:
runs-on: ubuntu-latest

steps:
Expand All @@ -24,13 +24,43 @@ jobs:
shared:
- 'shared/**'
- name: Validate API
if: steps.filter.outputs.api == 'true' || steps.filter.outputs.shared == 'true'
- name: Restore node_modules cache
id: deps-cache
uses: martijnhols/actions-cache/restore@v3
with:
path: api/node_modules
key: ${{ runner.os }}-build-api-deps-cache-${{ hashFiles('api/package-lock.json') }}
restore-keys: |
${{ runner.os }}-build-${{ env.cache-name }}-
${{ runner.os }}-build-
${{ runner.os }}-
- name: Install Dependencies
if: steps.deps-cache.outputs.cache-hit != 'true'
run: |
cd api
npm install
- name: Cache node modules
if: steps.deps-cache.outputs.cache-hit != 'true'
uses: martijnhols/actions-cache/save@v3
with:
path: api/node_modules
key: ${{ runner.os }}-build-api-deps-cache-${{ hashFiles('api/package-lock.json') }}

- name: Run static code analysis
if: steps.filter.outputs.api == 'true' || steps.filter.outputs.shared == 'true'
run: |
cd api
npm run lint
- name: Run unit test
if: steps.filter.outputs.api == 'true' || steps.filter.outputs.shared == 'true'
run: |
cd api
npm run test:unit
- name: Build the Docker image for API
if: steps.filter.outputs.api == 'true' || steps.filter.outputs.shared == 'true'
run: docker build . --file ./api/Dockerfile
2 changes: 1 addition & 1 deletion api/src/middlewares/userMiddleware.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ export const kvStore = {
return cacheEngine.getFromCache(key);
}
},
async put(key: string, value: any) {
async put(key: string, value: unknown) {
cacheEngine.storeInCache(key, value);
}
};
Expand Down
2 changes: 1 addition & 1 deletion api/src/routers/apiRouter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ export const apiRouter = new OpenAPIHono();
function registerApiVersion(version: string, baseRouter: OpenAPIHono, versionRoutes: OpenAPIHono[]) {
const versionRouter = new OpenAPIHono();

let servers = [{ url: `https://api.cloudmos.io/${version}`, description: "Production" }];
const servers = [{ url: `https://api.cloudmos.io/${version}`, description: "Production" }];
if (!isProd) {
servers.unshift({ url: `http://localhost:3080/${version}`, description: "Localhost" });
}
Expand Down
4 changes: 2 additions & 2 deletions api/src/routers/internalRouter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ internalRouter.get("/provider-versions", async (c) => {
group: ["hostUri", "akashVersion"]
});

let grouped: { version: string; providers: string[] }[] = [];
const grouped: { version: string; providers: string[] }[] = [];

for (const provider of providers) {
const existing = grouped.find((x) => x.version === provider.akashVersion);
Expand Down Expand Up @@ -49,7 +49,7 @@ internalRouter.get("/provider-versions", async (c) => {
.reduce((acc, x) => {
acc[x.version] = x;
return acc;
}, {} as any);
}, {});

return c.json(sorted);
});
Expand Down
2 changes: 1 addition & 1 deletion api/src/services/db/statsService.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { Day } from "@shared/dbSchemas/base";
import { AkashBlock as Block, Provider } from "@shared/dbSchemas/akash";
import { AkashBlock as Block } from "@shared/dbSchemas/akash";
import { subHours } from "date-fns";
import { Op, QueryTypes } from "sequelize";
import { chainDb } from "@src/db/dbConnection";
Expand Down
6 changes: 4 additions & 2 deletions api/src/verify-rsa-jwt-cloudflare-worker-main/index.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import { GeneralKeyValueStore, KVNamespaceOrKeyValueStore, KVStore } from './use-kv-store';

export { getJwks } from './get-jwks';
export type { Jwks } from './get-jwks';
export { getPayloadFromContext, verifyRsaJwt } from './hono-middleware';
Expand All @@ -7,12 +9,12 @@ export type {
GeneralKeyValueStore,
KVNamespaceOrKeyValueStore,
KVStore,
} from './use-kv-store';
};
export { verify } from './verify';
export type { VerificationResult } from './verify';

export type VerifyRsaJwtEnv = {
VERIFY_RSA_JWT: any;
VERIFY_RSA_JWT: KVNamespaceOrKeyValueStore;
VERIFY_RSA_JWT_JWKS_CACHE_KEY: string;
JWKS_URI: string;
};
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ export type GeneralKeyValueStore = {
put: (
key: string,
value: string,
options: any,
options: Record<string, unknown>,
) => Promise<void>;
};
export type KVNamespaceOrKeyValueStore = /*KVNamespace | */GeneralKeyValueStore;
Expand Down

0 comments on commit c6f2a6e

Please sign in to comment.