Skip to content
This repository has been archived by the owner on Mar 14, 2024. It is now read-only.

Commit

Permalink
test: add test cases
Browse files Browse the repository at this point in the history
  • Loading branch information
tomwwinter committed Feb 28, 2024
1 parent 2a69952 commit a4489d7
Show file tree
Hide file tree
Showing 6 changed files with 329 additions and 142 deletions.
2 changes: 1 addition & 1 deletion src/config/app.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -30,4 +30,4 @@ SENTRY:
ENABLED: false
INSTANCE_NAME: local-development # can be personalised in .env -> local-development-<your-name>
ENVIRONMENT: local # local | development | production
DNS:
DNS: ''
25 changes: 25 additions & 0 deletions src/couchdb/couch-db-client.interface.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
import { Observable } from 'rxjs';
import { CouchDbChangesResponse } from './dtos';
import { AxiosResponse } from 'axios';

export interface ICouchDbClient {
changes(request: { config?: any }): Observable<CouchDbChangesResponse>;

headDatabaseDocument(request: {
documentId: string;
config?: any;
}): Observable<AxiosResponse<any, any>>;

getDatabaseDocument<T>(request: {
documentId: string;
config?: any;
}): Observable<T>;

find<T>(request: { query: object; config: any }): Observable<T>;

putDatabaseDocument<T>(request: {
documentId: string;
body: any;
config: any;
}): Observable<T>;
}
10 changes: 7 additions & 3 deletions src/couchdb/couch-db-client.service.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
import { Logger } from '@nestjs/common';
import { catchError, map, Observable, of, switchMap } from 'rxjs';
import { HttpService } from '@nestjs/axios';
import { AxiosHeaders } from 'axios';
import { AxiosHeaders, AxiosResponse } from 'axios';
import { CouchDbChangesResponse } from './dtos';
import { ICouchDbClient } from './couch-db-client.interface';

export class CouchDbClientConfig {
BASE_URL = '';
Expand All @@ -11,7 +12,7 @@ export class CouchDbClientConfig {
BASIC_AUTH_PASSWORD = '';
}

export class CouchDbClient {
export class CouchDbClient implements ICouchDbClient {
private readonly logger = new Logger(CouchDbClient.name);

constructor(private httpService: HttpService) {}
Expand All @@ -30,7 +31,10 @@ export class CouchDbClient {
);
}

headDatabaseDocument(request: { documentId: string; config?: any }) {
headDatabaseDocument(request: {
documentId: string;
config?: any;
}): Observable<AxiosResponse<any, any>> {
return this.httpService.head(`${request.documentId}`, request.config).pipe(
catchError((err) => {
if (err.response.status !== 404) {
Expand Down
42 changes: 32 additions & 10 deletions src/query/sqs/dtos.ts
Original file line number Diff line number Diff line change
@@ -1,15 +1,37 @@
import * as crypto from 'crypto';

export class SqsSchema {
readonly language: 'sqlite';
readonly configVersion: string;
readonly sql: {
tables: SqlTables;
// Optional SQL indices
indexes: string[];
// Further options
options: SqlOptions;
};

constructor(
public sql: {
// SQL table definitions
tables: SqlTables;
// Optional SQL indices
indexes?: string[];
// Further options
options?: SqlOptions;
},
public language: 'sqlite' = 'sqlite',
) {}
tables: SqlTables,
indexes: string[],
options: SqlOptions,
language: 'sqlite' = 'sqlite',
) {
this.sql = {
tables: tables,
indexes: indexes,
options: options,
};
this.language = language;
this.configVersion = this.asHash();
}

private asHash(): string {
return crypto
.createHash('sha256')
.update(JSON.stringify(this.sql))
.digest('hex');
}
}

type SqlTables = {
Expand Down
Loading

0 comments on commit a4489d7

Please sign in to comment.