Skip to content

Commit

Permalink
tests added chunkMap test for btm on Relation &
Browse files Browse the repository at this point in the history
  • Loading branch information
silverqx committed Aug 8, 2022
1 parent 99fce66 commit f667781
Showing 1 changed file with 30 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -191,6 +191,7 @@ private slots:
void chunkMap_EmptyResult() const;

void chunkMap_TemplatedReturnValue() const;
void chunkMap_TemplatedReturnValue_OnRelationRef() const;
void chunkMap_EnforceOrderBy_TemplatedReturnValue() const;
void chunkMap_EmptyResult_TemplatedReturnValue() const;

Expand Down Expand Up @@ -3246,6 +3247,35 @@ void tst_Model_Relations::chunkMap_TemplatedReturnValue() const
QCOMPARE(result, expectedResult);
}

void tst_Model_Relations::chunkMap_TemplatedReturnValue_OnRelationRef() const
{
QFETCH_GLOBAL(QString, connection);

ConnectionOverride::connection = connection;

/* Even if the chunkMap<> is called on the Relation & it can't crash or fail, it
should normally works but the pivot table will not be hydrated. */
auto result = Torrent::find(2)->tags()->orderBy(ID)
.chunkMap<QString>([](Tag &&model)
{
// Pivot table is not hydrated
Q_ASSERT(!model.relationLoaded("tagged"));

// Return the modify name directly
return QStringLiteral("%1_mapped").arg(model[NAME]->template value<QString>());
});

QVector<QString> expectedResult {
{"tag1_mapped"},
{"tag2_mapped"},
{"tag3_mapped"},
{"tag4_mapped"},
};

QVERIFY(expectedResult.size() == result.size());
QCOMPARE(result, expectedResult);
}

void
tst_Model_Relations::chunkMap_EnforceOrderBy_TemplatedReturnValue() const
{
Expand Down

0 comments on commit f667781

Please sign in to comment.