Skip to content
This repository has been archived by the owner on Jan 13, 2025. It is now read-only.

Commit

Permalink
Merge pull request #5 from cre8/tests
Browse files Browse the repository at this point in the history
add test runs to the ci
  • Loading branch information
cre8 authored Apr 28, 2024
2 parents a375420 + bd5f171 commit 10887a8
Show file tree
Hide file tree
Showing 52 changed files with 1,091 additions and 1,078 deletions.
29 changes: 28 additions & 1 deletion .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,36 @@ permissions:
contents: read
packages: write

jobs:
jobs:
build-and-test:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: pnpm/action-setup@v3
with:
version: 9
- name: Use Node.js 20
uses: actions/setup-node@v4
with:
node-version: 20
cache: 'pnpm'
- name: Install dependencies
run: pnpm install

- name: Build
run: pnpm build

- name: init env files
run: pnpm run init

- name: Test
run: pnpm test

build-and-push:
runs-on: ubuntu-latest
# only run this when it's a push to main
if: github.ref == 'refs/heads/main'
needs: build-and-test
steps:
- name: Checkout code
uses: actions/checkout@v4
Expand Down
61 changes: 32 additions & 29 deletions apps/backend/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -23,58 +23,61 @@
},
"dependencies": {
"@nestjs/axios": "^3.0.2",
"@nestjs/common": "^10.0.0",
"@nestjs/config": "^3.2.0",
"@nestjs/core": "^10.0.0",
"@nestjs/platform-express": "^10.0.0",
"@nestjs/swagger": "^7.3.0",
"@nestjs/common": "^10.3.8",
"@nestjs/config": "^3.2.2",
"@nestjs/core": "^10.3.8",
"@nestjs/platform-express": "^10.3.8",
"@nestjs/swagger": "^7.3.1",
"@nestjs/typeorm": "^10.0.2",
"@sd-jwt/crypto-nodejs": "^0.6.1",
"@sd-jwt/sd-jwt-vc": "^0.6.1",
"@sphereon/did-auth-siop": "^0.6.3",
"@sphereon/oid4vci-client": "^0.10.2",
"@sphereon/oid4vci-common": "^0.10.1",
"@sphereon/pex": "^3.3.1",
"@sphereon/ssi-types": "^0.21.0",
"@sphereon/did-auth-siop": "^0.6.4",
"@sphereon/oid4vci-client": "^0.10.3",
"@sphereon/oid4vci-common": "^0.10.3",
"@sphereon/pex": "^3.3.3",
"@sphereon/ssi-types": "^0.23.4",
"axios": "^1.6.8",
"class-transformer": "^0.5.1",
"class-validator": "^0.14.1",
"did-resolver": "^4.1.0",
"joi": "^17.12.2",
"jose": "^5.2.3",
"keycloak-connect": "^24.0.1",
"joi": "^17.13.0",
"jose": "^5.2.4",
"keycloak-connect": "^24.0.3",
"nest-keycloak-connect": "^1.10.0",
"pg": "^8.11.3",
"reflect-metadata": "^0.2.0",
"pg": "^8.11.5",
"reflect-metadata": "^0.2.2",
"rxjs": "^7.8.1",
"sqlite3": "^5.1.7",
"typeorm": "^0.3.20",
"uuid": "^9.0.1"
},
"devDependencies": {
"@nestjs/cli": "^10.0.0",
"@nestjs/schematics": "^10.0.0",
"@nestjs/testing": "^10.0.0",
"@types/express": "^4.17.17",
"@types/jest": "^29.5.2",
"@types/node": "^20.3.1",
"@types/supertest": "^6.0.0",
"jest": "^29.5.0",
"prettier": "^3.0.0",
"@nestjs/cli": "^10.3.2",
"@nestjs/schematics": "^10.1.1",
"@nestjs/testing": "^10.3.8",
"@types/express": "^4.17.21",
"@types/jest": "^29.5.12",
"@types/node": "^20.12.7",
"@types/supertest": "^6.0.2",
"jest": "^29.7.0",
"prettier": "^3.2.5",
"source-map-support": "^0.5.21",
"supertest": "^6.3.3",
"ts-jest": "^29.1.0",
"ts-loader": "^9.4.3",
"ts-node": "^10.9.1",
"supertest": "^6.3.4",
"ts-jest": "^29.1.2",
"ts-loader": "^9.5.1",
"ts-node": "^10.9.2",
"tsconfig-paths": "^4.2.0",
"typescript": "^5.1.3"
"typescript": "^5.4.5"
},
"jest": {
"moduleFileExtensions": [
"js",
"json",
"ts"
],
"moduleNameMapper": {
"^src/(.*)$": "<rootDir>/$1"
},
"rootDir": "src",
"testRegex": ".*\\.spec\\.ts$",
"transform": {
Expand Down
25 changes: 25 additions & 0 deletions apps/backend/src/app.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
import { Test, TestingModule } from '@nestjs/testing';
import { INestApplication } from '@nestjs/common';
import * as request from 'supertest';
import { AppController } from './app.controller';

describe('AppController', () => {
let app: INestApplication;

beforeEach(async () => {
const moduleFixture: TestingModule = await Test.createTestingModule({
controllers: [AppController],
}).compile();

app = moduleFixture.createNestApplication();
await app.init();
});

it('/GET health', () => {
return request(app.getHttpServer()).get('/health').expect(200).expect('ok');
});

afterAll(async () => {
await app.close();
});
});
20 changes: 0 additions & 20 deletions apps/backend/src/credentials/credentials.controller.spec.ts

This file was deleted.

2 changes: 1 addition & 1 deletion apps/backend/src/credentials/credentials.controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ export class CredentialsController {
@AuthenticatedUser() user: KeycloakUser
): Promise<CredentialResponse> {
//TODO: return the parsed values so the client does not have to decode it.
return this.credentialsService.findOne(id, user.sub).catch(() => {
return this.credentialsService.showOne(id, user.sub).catch(() => {
throw new ConflictException();
});
}
Expand Down
18 changes: 0 additions & 18 deletions apps/backend/src/credentials/credentials.service.spec.ts

This file was deleted.

28 changes: 15 additions & 13 deletions apps/backend/src/credentials/credentials.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,19 +35,21 @@ export class CredentialsService {
return this.credentialRepository.find({ where: { user } });
}

findOne(id: string, user: string): Promise<CredentialResponse> {
return this.credentialRepository
.findOneOrFail({ where: { id, user } })
.then(async (entry) => {
const sdjwtvc = await this.instance.decode(entry.value);
const claims = await sdjwtvc.getClaims<Record<string, unknown>>(digest);
entry.value = undefined;
entry.user = undefined;
return {
...entry,
credential: claims,
};
});
findOne(id: string, user: string) {
return this.credentialRepository.findOneOrFail({ where: { id, user } });
}

showOne(id: string, user: string): Promise<CredentialResponse> {
return this.findOne(id, user).then(async (entry) => {
const sdjwtvc = await this.instance.decode(entry.value);
const claims = await sdjwtvc.getClaims<Record<string, unknown>>(digest);
entry.value = undefined;
entry.user = undefined;
return {
...entry,
credential: claims,
};
});
}

remove(id: string, user: string) {
Expand Down
15 changes: 15 additions & 0 deletions apps/backend/src/history/dto/history-response.dto.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
import { ApiProperty } from '@nestjs/swagger';
import { History } from '../entities/history.entity';

class Disclosed {
key: string;
value: string;
}

export class HistoryResponse extends History {
/**
* The values that were presented
*/
@ApiProperty({ type: [Disclosed] })
disclosed: Disclosed[];
}
6 changes: 6 additions & 0 deletions apps/backend/src/history/entities/history.entity.ts
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,12 @@ export class History {
@Column()
status: HistoryStatus;

@Column({ nullable: true })
credentialType: string;

@Column({ nullable: true })
presentation: string;

/**
* Date of creation
*/
Expand Down
18 changes: 0 additions & 18 deletions apps/backend/src/history/history.controller.spec.ts

This file was deleted.

6 changes: 5 additions & 1 deletion apps/backend/src/history/history.controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import { ApiOAuth2, ApiOperation, ApiProperty, ApiTags } from '@nestjs/swagger';
import { AuthGuard, AuthenticatedUser } from 'nest-keycloak-connect';
import { HistoryService } from './history.service';
import { KeycloakUser } from 'src/auth/user';
import { HistoryResponse } from './dto/history-response.dto';

@UseGuards(AuthGuard)
@ApiOAuth2([])
Expand All @@ -19,7 +20,10 @@ export class HistoryController {

@ApiOperation({ summary: 'get one element' })
@Get(':id')
getOne(@AuthenticatedUser() user: KeycloakUser, @Param('id') id: string) {
getOne(
@AuthenticatedUser() user: KeycloakUser,
@Param('id') id: string
): Promise<HistoryResponse> {
return this.historyService.getOne(id, user.sub);
}

Expand Down
18 changes: 0 additions & 18 deletions apps/backend/src/history/history.service.spec.ts

This file was deleted.

Loading

0 comments on commit 10887a8

Please sign in to comment.