-
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.
Merge pull request #72 from geoadmin/feature/assets-67-update-elastic…
…search-index #67 update elasticsearch index local
- Loading branch information
Showing
12 changed files
with
248 additions
and
162 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
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(); | ||
}); | ||
|
||
}); |
Oops, something went wrong.