-
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
1 parent
74cae68
commit 6ae07bb
Showing
9 changed files
with
86 additions
and
64 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,3 @@ | ||
// stampService.js | ||
import { StampRepository } from '../repository/stampRepository'; | ||
|
||
export class StampService { | ||
|
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,3 +1,4 @@ | ||
module.exports = { | ||
testMatch: ["**/tests/**/*.[jt]s?(x)", "**/?(*.)+(spec|test).[tj]s?(x)"], | ||
preset: 'ts-jest', | ||
testMatch: ['**/tests/**/*.[jt]s?(x)', '**/?(*.)+(spec|test).[tj]s?(x)'], | ||
}; |
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 was deleted.
Oops, something went wrong.
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,41 @@ | ||
// StampRepository.test.ts | ||
import OpenAI from 'openai'; | ||
import { StampRepository } from '../app/repository/stampRepository'; | ||
|
||
describe('StampRepository', () => { | ||
let openAIInstance: OpenAI; | ||
let stampRepository: StampRepository; | ||
const mockImageUrl = 'https://example.com/image.png'; | ||
|
||
beforeEach(() => { | ||
openAIInstance = new OpenAI({ apiKey: 'dummy-api-key' }); | ||
stampRepository = new StampRepository(openAIInstance); | ||
}); | ||
|
||
it('should generate an image URL successfully', async () => { | ||
jest.spyOn(openAIInstance.images, 'generate').mockResolvedValue({ | ||
created: 0, | ||
data: [{ url: mockImageUrl }], | ||
}); | ||
|
||
const prompt = 'test prompt'; | ||
const imageUrl = await stampRepository.generateImage(prompt); | ||
expect(imageUrl).toBe(mockImageUrl); | ||
expect(openAIInstance.images.generate).toHaveBeenCalledWith({ | ||
model: 'dall-e-3', | ||
prompt, | ||
n: 1, | ||
size: '1024x1024', | ||
}); | ||
}); | ||
|
||
it('should throw an error when image generation fails', async () => { | ||
jest | ||
.spyOn(openAIInstance.images, 'generate') | ||
.mockRejectedValue(new Error('API call failed')); | ||
|
||
await expect(stampRepository.generateImage('test prompt')).rejects.toThrow( | ||
'Image generation failed' | ||
); | ||
}); | ||
}); |
This file was deleted.
Oops, something went wrong.
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,31 @@ | ||
// stampService.test.js | ||
import { StampRepository } from '../app/repository/stampRepository'; | ||
import { StampService } from '../app/service/stampService'; | ||
|
||
describe('StampService', () => { | ||
let service: StampService; | ||
const template = 'Template: '; | ||
const mockImageUrl = 'https://example.com/image.png'; | ||
|
||
beforeEach(() => { | ||
jest.clearAllMocks(); | ||
service = new StampService(template, StampRepository.prototype); | ||
|
||
jest | ||
.spyOn(StampRepository.prototype, 'generateImage') | ||
.mockImplementation((prompt) => { | ||
return Promise.resolve(mockImageUrl); | ||
}); | ||
}); | ||
|
||
it('should generate an image URL using the provided template and input', async () => { | ||
const input = 'test input'; | ||
const result = await service.generateImageUrl(input); | ||
|
||
const expectedPrompt = template + input; | ||
expect(StampRepository.prototype.generateImage).toHaveBeenCalledWith( | ||
expectedPrompt | ||
); | ||
expect(result).toBe(mockImageUrl); | ||
}); | ||
}); |
Empty file.
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