文章未來將更新於:
https://kevinyay945.com/golang-project-design/anki-support/design-normal-anki-note-operator/
接下來我們要實做Normal Anki Note的測試案例
在我們的卡片中,預計希望的流程如下
當預計的實做流程出來後,測試的內容就可以像下面的內容一樣寫出來
func (t *OperatorSuite) Test_normal_operator() {
fields := map[string]FieldData{
"Expression": {Value: "test expression value"},
"Meaning": {Value: "test meaning value"},
"Reading": {Value: "test reading value"},
"Japanese-ToSound": {Value: "test japanese to sound value"},
"JapaneseSentence": {Value: "test japanese hiragana sentence value"},
"JapaneseSentence-ToSound": {Value: "test japanese sentence to sound value"},
"JapaneseSentence-ToChinese": {Value: "test japanese sentence to chinese value"},
"Japanese-Note": {Value: "test japanese note value"},
"Japanese-ToChineseNote": {Value: "test japanese to chinese note value"},
"Answer-Note": {Value: "test answer note value"},
}
note := Note{
Id: 123,
ModelName: "Japanese (recognition&recall)",
Fields: fields,
Tags: []string{"anki-helper-vocabulary-todo"},
}
japaneseSentence := "test japanese sentence"
rememberVocabularyList := []string{"vocabulary1", "vocabulary2"}
expressionVoicePath := "expression/file/path.mp3"
japaneseSentenceVoicePath := "japanese/sentence/file/path.mp3"
// expression to Japanese-ToSound by text to speech
t.mockTextToSpeecher.EXPECT().
GetJapaneseSound(fields["Expression"].Value).
Return(expressionVoicePath, nil)
// expression to JapaneseSentence and JapaneseSentence-ToChinese and JapaneseSentence-ToSound.Name by gpt
t.mockGPTer.EXPECT().
MakeJapaneseSentence(fields["Expression"].Value, fields["Meaning"].Value, rememberVocabularyList).
Return(japaneseSentence, fields["JapaneseSentence"].Value, fields["JapaneseSentence-ToChinese"].Value, nil)
// JapaneseSentence to JapaneseSentence-ToSound by text to speech
t.mockTextToSpeecher.EXPECT().
GetJapaneseSound(japaneseSentence).
Return(japaneseSentenceVoicePath, nil)
// ankier update note by id with expect data
t.mockAnkier.EXPECT().
UpdateNoteById(note.Id, note, []Audio{
{
Path: expressionVoicePath,
Filename: fmt.Sprintf("[Sound:%s.mp3]", fields["Meaning"].Value),
Fields: []string{"Japanese-ToSound"},
},
{
Path: japaneseSentenceVoicePath,
Filename: fmt.Sprintf("[Sound:%s.mp3]", japaneseSentence),
Fields: []string{"JapaneseSentence-ToSound"},
},
}).
Return(nil)
// delete todo tag in anki card
t.mockAnkier.EXPECT().DeleteNoteTagFromNoteId(note.Id, AnkiTodoTagName).Return(nil)
// add done tag at anki card
t.mockAnkier.EXPECT().AddNoteTagFromNoteId(note.Id, AnkiDoneTagName).Return(nil)
operator, err := t.generator.GetByNote(Note{
Id: note.Id,
ModelName: note.ModelName,
Fields: map[string]FieldData{
"Expression": fields["Expression"],
"Meaning": fields["Meaning"],
"Reading": fields["Reading"],
"Japanese-ToSound": {Value: ""},
"JapaneseSentence": {Value: ""},
"JapaneseSentence-ToSound": {Value: ""},
"JapaneseSentence-ToChinese": {Value: ""},
"Japanese-Note": {Value: "test japanese note value"},
"Japanese-ToChineseNote": {Value: "test japanese to chinese note value"},
"Answer-Note": {Value: "test answer note value"},
},
Tags: []string{"anki-helper-vocabulary-todo"},
})
t.NoError(err)
err = operator.Do()
t.NoError(err)
}
下一篇就可以開始implement需要的內容