diff --git a/model/questionnaires_impl.go b/model/questionnaires_impl.go index eb93db5f..e0dbb922 100755 --- a/model/questionnaires_impl.go +++ b/model/questionnaires_impl.go @@ -256,7 +256,7 @@ func (*Questionnaire) GetQuestionnaires(ctx context.Context, userID string, sort err = query. Limit(20). Offset(offset). - Group("questionnaires.id"). + Group("questionnaires.id, targets.user_traqid"). Select("questionnaires.*, (targets.user_traqid = ? OR targets.user_traqid = 'traP') AS is_targeted", userID). Find(&questionnaires).Error if errors.Is(err, context.DeadlineExceeded) { diff --git a/model/questionnaires_test.go b/model/questionnaires_test.go index dde2ed33..934b4ef4 100644 --- a/model/questionnaires_test.go +++ b/model/questionnaires_test.go @@ -1064,166 +1064,51 @@ func getQuestionnairesTest(t *testing.T) { }, }, { - description: "userID:valid, sort:created_at, search:no, page:1", - args: args{ - userID: questionnairesTestUserID, - sort: "created_at", - search: "", - pageNum: 1, - onlyTargetingMe: false, - onlyAdministratedByMe: true, - }, - }, - { - description: "userID:valid, sort:-created_at, search:no, page:1", - args: args{ - userID: questionnairesTestUserID, - sort: "-created_at", - search: "", - pageNum: 1, - onlyTargetingMe: false, - onlyAdministratedByMe: true, - }, - }, - { - description: "userID:valid, sort:title, search:no, page:1", - args: args{ - userID: questionnairesTestUserID, - sort: "title", - search: "", - pageNum: 1, - onlyTargetingMe: false, - onlyAdministratedByMe: true, - }, - }, - { - description: "userID:valid, sort:-title, search:no, page:1", - args: args{ - userID: questionnairesTestUserID, - sort: "-title", - search: "", - pageNum: 1, - onlyTargetingMe: false, - onlyAdministratedByMe: true, - }, - }, - { - description: "userID:valid, sort:modified_at, search:no, page:1", - args: args{ - userID: questionnairesTestUserID, - sort: "modified_at", - search: "", - pageNum: 1, - onlyTargetingMe: false, - onlyAdministratedByMe: true, - }, - }, - { - description: "userID:valid, sort:-modified_at, search:no, page:1", - args: args{ - userID: questionnairesTestUserID, - sort: "-modified_at", - search: "", - pageNum: 1, - onlyTargetingMe: false, - onlyAdministratedByMe: true, - }, - }, - { - description: "userID:valid, sort:no, search:GetQuestionnaireTest$, page:1", - args: args{ - userID: questionnairesTestUserID, - sort: "", - search: "GetQuestionnaireTest$", - pageNum: 1, - onlyTargetingMe: false, - onlyAdministratedByMe: true, - }, - expect: expect{ - isCheckLen: true, - length: 4, - }, - }, - { - description: "userID:valid, sort:no, search:no, page:2", + description: "userID:valid, sort:no, search:no, page:1, onlytargetted", args: args{ userID: questionnairesTestUserID, sort: "", search: "", - pageNum: 2, - onlyTargetingMe: true, - onlyAdministratedByMe: true, - }, - }, - { - description: "too large page", - args: args{ - userID: questionnairesTestUserID, - sort: "", - search: "", - pageNum: 100000, + pageNum: 1, onlyTargetingMe: true, onlyAdministratedByMe: true, }, - expect: expect{ - isErr: true, - err: ErrTooLargePageNum, - }, }, { - description: "userID:valid, sort:no, search:no, page:1, nontargetted", + description: "userID:valid, sort:no, search:no, page:1", args: args{ userID: questionnairesTestUserID, sort: "", search: "", pageNum: 1, - onlyTargetingMe: true, - onlyAdministratedByMe: true, + onlyTargetingMe: false, + onlyAdministratedByMe: false, }, }, { - description: "userID:valid, sort:no, search:notFoundQuestionnaire, page:1", + description: "userID:valid, sort:no, search:no, page:1, onlytargetted, onlyadministrated", args: args{ userID: questionnairesTestUserID, sort: "", - search: "notFoundQuestionnaire", + search: "", pageNum: 1, onlyTargetingMe: true, - onlyAdministratedByMe: true, - }, - expect: expect{ - isCheckLen: false, - length: 0, + onlyAdministratedByMe: false, }, }, { - description: "userID:valid, sort:invalid, search:no, page:1", + description: "userID:valid, sort:created_at, search:no, page:1", args: args{ userID: questionnairesTestUserID, - sort: "hogehoge", + sort: "created_at", search: "", pageNum: 1, onlyTargetingMe: false, onlyAdministratedByMe: true, }, - expect: expect{ - isErr: true, - err: ErrInvalidSortParam, - }, }, { - description: "userID:valid, sort:no, search:no, page:1", - args: args{ - userID: questionnairesTestUserID, - sort: "", - search: "", - pageNum: 1, - onlyTargetingMe: false, - onlyAdministratedByMe: false, - }, - }, - { - description: "userID:valid, sort:created_at, search:no, page:1", + description: "userID:valid, sort:created_at, search:no, page:1, onlyadministrated", args: args{ userID: questionnairesTestUserID, sort: "created_at", @@ -1303,6 +1188,21 @@ func getQuestionnairesTest(t *testing.T) { length: 4, }, }, + { + description: "userID:valid, sort:no, search:GetQuestionnaireTest$, page:1, onlyadministrated", + args: args{ + userID: questionnairesTestUserID, + sort: "", + search: "GetQuestionnaireTest$", + pageNum: 1, + onlyTargetingMe: false, + onlyAdministratedByMe: true, + }, + expect: expect{ + isCheckLen: true, + length: 2, + }, + }, { description: "userID:valid, sort:no, search:no, page:2", args: args{ @@ -1310,7 +1210,7 @@ func getQuestionnairesTest(t *testing.T) { sort: "", search: "", pageNum: 2, - onlyTargetingMe: true, + onlyTargetingMe: false, onlyAdministratedByMe: false, }, }, @@ -1321,7 +1221,7 @@ func getQuestionnairesTest(t *testing.T) { sort: "", search: "", pageNum: 100000, - onlyTargetingMe: true, + onlyTargetingMe: false, onlyAdministratedByMe: false, }, expect: expect{ @@ -1329,17 +1229,6 @@ func getQuestionnairesTest(t *testing.T) { err: ErrTooLargePageNum, }, }, - { - description: "userID:valid, sort:no, search:no, page:1, nontargetted", - args: args{ - userID: questionnairesTestUserID, - sort: "", - search: "", - pageNum: 1, - onlyTargetingMe: true, - onlyAdministratedByMe: false, - }, - }, { description: "userID:valid, sort:no, search:notFoundQuestionnaire, page:1", args: args{ @@ -1347,11 +1236,11 @@ func getQuestionnairesTest(t *testing.T) { sort: "", search: "notFoundQuestionnaire", pageNum: 1, - onlyTargetingMe: true, + onlyTargetingMe: false, onlyAdministratedByMe: false, }, expect: expect{ - isCheckLen: false, + isCheckLen: true, length: 0, }, }, @@ -1403,13 +1292,13 @@ func getQuestionnairesTest(t *testing.T) { actualQuestionnaireIDs = append(actualQuestionnaireIDs, questionnaire.ID) } if testCase.args.onlyTargetingMe { - for _, targettedQuestionnaireID := range userTargetMap[questionnairesTestUserID] { - assertion.NotContains(actualQuestionnaireIDs, targettedQuestionnaireID, testCase.description, "not contain(targetted)") + for _, actualQuestionnaireID := range actualQuestionnaireIDs { + assertion.Contains(userTargetMap[questionnairesTestUserID], actualQuestionnaireID, testCase.description, "contain(targetted)") } } if testCase.args.onlyAdministratedByMe { - for _, targettedQuestionnaireID := range userTargetMap[questionnairesTestUserID] { - assertion.NotContains(actualQuestionnaireIDs, targettedQuestionnaireID, testCase.description, "not contain(administrated)") + for _, actualQuestionnaireID := range actualQuestionnaireIDs { + assertion.Contains(userAdministratorMap[questionnairesTestUserID], actualQuestionnaireID, testCase.description, "contain(administrated)") } } for _, deletedQuestionnaireID := range deletedQuestionnaireIDs {