-
-
Notifications
You must be signed in to change notification settings - Fork 1
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
115 changed files
with
14,404 additions
and
5,247 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
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
113 changes: 113 additions & 0 deletions
113
...lication/use_cases/change_active_ocr_template/change_active_ocr_template.use_case.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,113 @@ | ||
import { SettingsPreset } from "../../../domain/settings_preset/settings_preset"; | ||
import { DataSource } from 'typeorm'; | ||
import { Language } from "../../../domain/language/language"; | ||
import { Profile } from "../../../domain/profile/profile"; | ||
import { ProfileTypeOrmSchema } from "../../../infra/db/typeorm/profile/profile.schema"; | ||
import { SettingsPresetTypeOrmSchema } from "../../../infra/db/typeorm/settings_preset/settings_preset.schema"; | ||
import { LanguageTypeOrmSchema } from "../../../infra/db/typeorm/language/language.schema"; | ||
import ProfileTypeOrmRepository from "../../../infra/db/typeorm/profile/profile.typeorm.repository"; | ||
import LanguageTypeOrmRepository from "../../../infra/db/typeorm/language/language.typeorm.repository"; | ||
import { ChangeActiveOcrTemplateUseCase, ChangeActiveOcrTemplate_Input } from "./change_active_ocr_template.use_case"; | ||
import { OcrTemplateTypeOrmSchema } from "../../../infra/db/typeorm/ocr_template/ocr_template.schema"; | ||
import { OcrTargetRegionTypeOrmSchema } from "../../../infra/db/typeorm/ocr_template/ocr_target_region/ocr_target_region.schema"; | ||
import { OcrTemplate } from "../../../domain/ocr_template/ocr_template"; | ||
import OcrTemplateTypeOrmRepository from "../../../infra/db/typeorm/ocr_template/ocr_template.typeorm.repository"; | ||
import { OcrTargetRegion } from "../../../domain/ocr_template/ocr_target_region/ocr_target_region"; | ||
|
||
describe("ChangeActiveOcrTemplateUseCase tests", () => { | ||
|
||
let changeActiveOcrTemplateUseCase: ChangeActiveOcrTemplateUseCase; | ||
|
||
let initialProfile: Profile; | ||
|
||
let profilesRepo: ProfileTypeOrmRepository; | ||
|
||
let ocrTemplate: OcrTemplate; | ||
|
||
beforeEach( async () => { | ||
|
||
let dataSource = new DataSource({ | ||
type: 'sqlite', | ||
database: ':memory:', | ||
synchronize: true, | ||
logging: false, | ||
entities: [ | ||
ProfileTypeOrmSchema, | ||
SettingsPresetTypeOrmSchema, | ||
LanguageTypeOrmSchema, | ||
OcrTemplateTypeOrmSchema, | ||
OcrTargetRegionTypeOrmSchema | ||
], | ||
}); | ||
|
||
await dataSource.initialize(); | ||
|
||
const settingsPreset = SettingsPreset.create(); | ||
await dataSource.getRepository( SettingsPreset ).insert( settingsPreset ); | ||
|
||
const languageJa = Language.create({ name: 'japanese', two_letter_code: 'ja' }); | ||
await dataSource.getRepository( Language ).insert( languageJa ); | ||
|
||
|
||
const ocrTemplatesRepo = new OcrTemplateTypeOrmRepository( | ||
dataSource.getRepository( OcrTemplate ), | ||
dataSource.getRepository( OcrTargetRegion ) | ||
); | ||
ocrTemplate = OcrTemplate.create({ | ||
name: 'Template 1', | ||
image: Buffer.from('') | ||
}); | ||
await ocrTemplatesRepo.insert( ocrTemplate ); | ||
ocrTemplate = await ocrTemplatesRepo.findOne({ | ||
id: ocrTemplate.id | ||
}) as OcrTemplate; | ||
|
||
profilesRepo = new ProfileTypeOrmRepository( dataSource.getRepository( Profile ) ); | ||
|
||
|
||
initialProfile = Profile.create({ | ||
active_ocr_language: languageJa, | ||
active_settings_preset: settingsPreset, | ||
}); | ||
|
||
await profilesRepo.insert( initialProfile ); | ||
|
||
changeActiveOcrTemplateUseCase = new ChangeActiveOcrTemplateUseCase({ | ||
profilesRepo, | ||
ocrTemplatesRepo | ||
}); | ||
|
||
}); | ||
|
||
it("should change the active ocr template from null to a ocr template", async () => { | ||
|
||
const input: ChangeActiveOcrTemplate_Input = { | ||
profileId: initialProfile.id, | ||
ocrTemplateId: ocrTemplate.id | ||
}; | ||
|
||
await changeActiveOcrTemplateUseCase.execute( input ); | ||
|
||
const currentProfile = await profilesRepo.findOne({ id: initialProfile.id }); | ||
|
||
expect( currentProfile?.active_ocr_template ) | ||
.toStrictEqual( ocrTemplate ); | ||
}); | ||
|
||
|
||
it("should change the active ocr template to null", async () => { | ||
|
||
const input: ChangeActiveOcrTemplate_Input = { | ||
profileId: initialProfile.id, | ||
ocrTemplateId: null | ||
}; | ||
|
||
await changeActiveOcrTemplateUseCase.execute( input ); | ||
|
||
const currentProfile = await profilesRepo.findOne({ id: initialProfile.id }); | ||
|
||
expect( currentProfile?.active_ocr_template ) | ||
.toStrictEqual( null ); | ||
}); | ||
|
||
}); |
50 changes: 50 additions & 0 deletions
50
...e/application/use_cases/change_active_ocr_template/change_active_ocr_template.use_case.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,50 @@ | ||
import { Language } from "../../../domain/language/language"; | ||
import { LanguageRepository } from "../../../domain/language/language.repository"; | ||
import { OcrTemplate, OcrTemplateId } from "../../../domain/ocr_template/ocr_template"; | ||
import { OcrTemplateRepository } from "../../../domain/ocr_template/ocr_template.repository"; | ||
import { Profile } from "../../../domain/profile/profile"; | ||
import { ProfileRepository } from "../../../domain/profile/profile.repository"; | ||
|
||
|
||
export type ChangeActiveOcrTemplate_Input = { | ||
ocrTemplateId: OcrTemplateId | null; // Two letters | ||
profileId: string; | ||
} | ||
|
||
export class ChangeActiveOcrTemplateUseCase { | ||
|
||
private profilesRepo: ProfileRepository; | ||
private ocrTemplatesRepo: OcrTemplateRepository; | ||
|
||
constructor( input: { | ||
profilesRepo: ProfileRepository; | ||
ocrTemplatesRepo: OcrTemplateRepository; | ||
}) { | ||
this.profilesRepo = input.profilesRepo; | ||
this.ocrTemplatesRepo = input.ocrTemplatesRepo; | ||
} | ||
|
||
async execute( input: ChangeActiveOcrTemplate_Input ): Promise< OcrTemplate | null > { | ||
|
||
let ocrTemplate: OcrTemplate | null = null; | ||
|
||
if ( input?.ocrTemplateId ) { | ||
ocrTemplate = await this.ocrTemplatesRepo.findOne({ | ||
id: input.ocrTemplateId, | ||
}); | ||
} | ||
|
||
const profile: Profile | null = await this.profilesRepo.findOne({ | ||
id: input.profileId | ||
}); | ||
|
||
if ( !profile ) | ||
return null; | ||
|
||
profile.active_ocr_template = ocrTemplate; | ||
|
||
await this.profilesRepo.update( profile ); | ||
|
||
return ocrTemplate; | ||
} | ||
} |
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
Oops, something went wrong.