-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
11 changed files
with
243 additions
and
7 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
107 changes: 107 additions & 0 deletions
107
apps/server-asset-sg/src/app/contact-edit/contact-edit.service.spec.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,107 @@ | ||
import { Test, TestingModule } from '@nestjs/testing'; | ||
import { left, right } from 'fp-ts/Either'; | ||
|
||
import { Contact, PatchContact } from '@asset-sg/shared'; | ||
|
||
import { PrismaService } from '../prisma/prisma.service'; | ||
|
||
import { ContactEditService } from './contact-edit.service'; | ||
|
||
|
||
jest.mock('../prisma/prisma.service'); | ||
|
||
const mockPatchContact: PatchContact = { | ||
name: 'John Doe', | ||
street: '123 Main Street', | ||
houseNumber: '1A', | ||
plz: '12345', | ||
locality: 'City', | ||
country: 'Country', | ||
telephone: '123-456-7890', | ||
email: '[email protected]', | ||
website: 'www.example.com', | ||
contactKindItemCode: '123' | ||
}; | ||
const mockContact: Contact = { | ||
id: 1, | ||
contactKindItemCode: '123', | ||
name: 'John Doe', | ||
street: '123 Main Street', | ||
houseNumber: '1A', | ||
plz: '12345', | ||
locality: 'City', | ||
country: 'Country', | ||
telephone: '123-456-7890', | ||
email: '[email protected]', | ||
website: 'www.example.com' | ||
}; | ||
|
||
const mockPrisma = { | ||
contact: {} | ||
}; | ||
|
||
|
||
describe('ContactEditService', () => { | ||
let service: ContactEditService; | ||
let prismaService: PrismaService; | ||
|
||
beforeEach(async () => { | ||
const module: TestingModule = await Test.createTestingModule({ | ||
providers: [ | ||
ContactEditService, | ||
{ | ||
provide: PrismaService, | ||
useValue: mockPrisma, | ||
}, | ||
], | ||
}).compile(); | ||
|
||
service = module.get<ContactEditService>(ContactEditService); | ||
prismaService = module.get<PrismaService>(PrismaService); | ||
|
||
}); | ||
|
||
it('should be defined', () => { | ||
expect(service).toBeDefined(); | ||
}); | ||
|
||
it('should create a contact', async () => { | ||
prismaService.contact.create = jest.fn().mockResolvedValue(mockContact); | ||
|
||
const result = await service.createContact(mockPatchContact)(); | ||
|
||
expect(result).toEqual(right(mockContact)); | ||
expect(prismaService.contact.create).toHaveBeenCalledWith({ data: mockPatchContact }); | ||
}); | ||
|
||
it('should update a contact', async () => { | ||
const mockContactId = 1; | ||
|
||
prismaService.contact.update = jest.fn().mockResolvedValue(mockPatchContact); | ||
prismaService.contact.findFirstOrThrow = jest.fn().mockResolvedValue(mockContact); | ||
|
||
const result = await service.updateContact(mockContactId, mockContact)(); | ||
|
||
expect(result).toEqual(right(mockContact)); | ||
expect(prismaService.contact.update).toHaveBeenCalledWith({ where: { contactId: mockContactId }, data: mockContact }); | ||
}); | ||
|
||
it('should handle errors when creating a contact', async () => { | ||
prismaService.contact.create = jest.fn().mockRejectedValue(new Error('Test error')); | ||
|
||
const result = await service.createContact(mockContact)(); | ||
|
||
expect(result).toEqual(left(new Error())); | ||
expect(prismaService.contact.create).toHaveBeenCalledWith({ data: mockContact }); | ||
}); | ||
|
||
it('should handle errors when updating a contact', async () => { | ||
const mockContactId = 1; | ||
prismaService.contact.update = jest.fn().mockRejectedValue(new Error('Test error')); | ||
|
||
const result = await service.updateContact(mockContactId, mockContact)(); | ||
|
||
expect(result).toEqual(left(new Error())); | ||
expect(prismaService.contact.update).toHaveBeenCalledWith({ where: { contactId: mockContactId }, data: mockContact }); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,5 @@ | ||
PUT /swissgeol_asset_asset | ||
|
||
|
||
PUT /swissgeol_asset_asset/_mapping | ||
{ | ||
"properties": { | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
17 changes: 17 additions & 0 deletions
17
libs/core/src/lib/ngrx-store-logger/ngrx-store-logger.spec.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
import { ActionReducer } from '@ngrx/store'; | ||
|
||
import { storeLogger } from './ngrx-store-logger'; | ||
|
||
describe('storeLogger', () => { | ||
|
||
it('should log state and action', () => { | ||
const consoleLogSpy = jest.spyOn(console, 'log').mockImplementation(() => { /* noop */ }); | ||
const metaReducer = storeLogger<string>(); | ||
const actionReducer: ActionReducer<string, any> = (state: string | undefined, action: any) => { return state || ''; }; | ||
Check warning on line 10 in libs/core/src/lib/ngrx-store-logger/ngrx-store-logger.spec.ts GitHub Actions / Build and run tests
Check warning on line 10 in libs/core/src/lib/ngrx-store-logger/ngrx-store-logger.spec.ts GitHub Actions / Build and run tests
|
||
|
||
metaReducer(actionReducer)('state', { type: 'test' }); | ||
|
||
expect(consoleLogSpy).toHaveBeenCalled(); | ||
}); | ||
|
||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,68 @@ | ||
import { NonError, deserializeError, isErrorLike, serializeError} from './serialize-error'; | ||
|
||
describe('serializeError', () => { | ||
it('should serialize error objects', () => { | ||
const error = new Error('Test error'); | ||
const serialized = serializeError(error); | ||
expect(serialized).toHaveProperty('name', 'Error'); | ||
expect(serialized).toHaveProperty('message', 'Test error'); | ||
expect(serialized).toHaveProperty('stack'); | ||
}); | ||
|
||
it('should serialize non-error objects', () => { | ||
const obj = { key: 'value' }; | ||
const serialized = serializeError(obj); | ||
expect(serialized).toEqual(obj); | ||
}); | ||
|
||
it('should serialize primitive values', () => { | ||
expect(serializeError('test')).toBe('test'); | ||
expect(serializeError(123)).toBe(123); | ||
}); | ||
}); | ||
|
||
describe('deserializeError', () => { | ||
it('should deserialize serialized error objects', () => { | ||
const error = new Error('Test error'); | ||
const serialized = serializeError(error); | ||
const deserialized = deserializeError(serialized); | ||
expect(deserialized).toBeInstanceOf(Error); | ||
expect(deserialized.message).toBe('Test error'); | ||
}); | ||
|
||
it('should return NonError for non-error objects', () => { | ||
const obj = { key: 'value' }; | ||
const deserialized = deserializeError(obj); | ||
expect(deserialized).toBeInstanceOf(NonError); | ||
expect(deserialized.message).toBe(JSON.stringify(obj)); | ||
}); | ||
|
||
it('should return NonError for primitive string', () => { | ||
const deserialized = deserializeError('test'); | ||
expect(deserialized).toBeInstanceOf(NonError); | ||
expect(deserialized.message).toBe('"test"'); | ||
}); | ||
|
||
it('should return NonError for primitive number', () => { | ||
const deserialized = deserializeError(123); | ||
expect(deserialized).toBeInstanceOf(NonError); | ||
expect(deserialized.message).toBe('123'); | ||
}); | ||
}); | ||
|
||
describe('isErrorLike', () => { | ||
it('should return true for error objects', () => { | ||
const error = new Error('Test error'); | ||
expect(isErrorLike(error)).toBe(true); | ||
}); | ||
|
||
it('should return false for non-error objects', () => { | ||
const obj = { key: 'value' }; | ||
expect(isErrorLike(obj)).toBe(false); | ||
}); | ||
|
||
it('should return false for primitive values', () => { | ||
expect(isErrorLike('test')).toBe(false); | ||
expect(isErrorLike(123)).toBe(false); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
import { HttpClientTestingModule, HttpTestingController } from '@angular/common/http/testing'; | ||
import { TestBed } from '@angular/core/testing'; | ||
|
||
import { Favourite, FavouriteService } from './favourite.service'; | ||
|
||
describe('FavouriteService', () => { | ||
let service: FavouriteService; | ||
let httpMock: HttpTestingController; | ||
|
||
beforeEach(() => { | ||
TestBed.configureTestingModule({ | ||
imports: [HttpClientTestingModule], | ||
providers: [FavouriteService] | ||
}); | ||
|
||
service = TestBed.inject(FavouriteService); | ||
httpMock = TestBed.inject(HttpTestingController); | ||
}); | ||
|
||
afterEach(() => { | ||
httpMock.verify(); // Ensure that there are no outstanding requests | ||
}); | ||
|
||
it('should be created', () => { | ||
expect(service).toBeTruthy(); | ||
}); | ||
|
||
it('should retrieve favourites from API via GET', () => { | ||
const dummyFavourites: Favourite[] = [{}, {}, {}]; | ||
|
||
service.getFavourites().subscribe(favourites => { | ||
expect(favourites.length).toBe(3); | ||
expect(favourites).toEqual(dummyFavourites); | ||
}); | ||
|
||
const request = httpMock.expectOne(`/api/user/favourite`); | ||
expect(request.request.method).toBe('GET'); | ||
request.flush(dummyFavourites); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters