@@ -44,6 +44,9 @@ TestMerginApi::~TestMerginApi() = default;
4444
4545void TestMerginApi::initTestCase ()
4646{
47+ // ping API was late and tests were failing because they didn't delete projects on start
48+ QSignalSpy spy ( mApi , &MerginApi::pingMerginFinished );
49+ spy.wait ( TestUtils::LONG_REPLY );
4750
4851 QString apiRoot, username, password, workspace;
4952 TestUtils::merginGetAuthCredentials ( mApi , apiRoot, username, password );
@@ -82,6 +85,11 @@ void TestMerginApi::initTestCase()
8285 mApiExtra = new MerginApi ( *mLocalProjectsExtra );
8386
8487 mApiExtra ->setApiRoot ( mApi ->apiRoot () );
88+
89+ // ping API was late and tests were failing because they didn't delete projects on start
90+ QSignalSpy spy2 ( mApiExtra , &MerginApi::pingMerginFinished );
91+ spy2.wait ( TestUtils::LONG_REPLY );
92+
8593 if ( TestUtils::needsToAuthorizeAgain ( mApiExtra , username ) )
8694 {
8795 TestUtils::authorizeUser ( mApiExtra , username, password );
@@ -331,9 +339,9 @@ void TestMerginApi::testCreateProjectTwice()
331339
332340 const QList<QVariant> arguments = spy2.takeFirst ();
333341 QVERIFY ( arguments.at ( 0 ).metaType ().id () == QMetaType::QString );
334- QVERIFY ( arguments.at ( 1 ).metaType ().id () == QMetaType::QString );
342+ QVERIFY ( arguments.at ( 1 ).metaType ().id () == QMetaType::Int );
335343
336- QCOMPARE ( arguments.at ( 1 ).toString (), QStringLiteral ( " Mergin API error: createProject " ) );
344+ QCOMPARE ( arguments.at ( 1 ).toInt (), 409 );
337345
338346 // Clean created project
339347 deleteRemoteProjectNow ( mApi , mWorkspaceName , projectName );
@@ -351,8 +359,8 @@ void TestMerginApi::testDeleteNonExistingProject()
351359
352360 const QList<QVariant> arguments = spy.takeFirst ();
353361 QVERIFY ( arguments.at ( 0 ).metaType ().id () == QMetaType::QString );
354- QVERIFY ( arguments.at ( 1 ).metaType ().id () == QMetaType::QString );
355- QCOMPARE ( arguments.at ( 1 ).toString (), QStringLiteral ( " Mergin API error: deleteProject " ) );
362+ QVERIFY ( arguments.at ( 1 ).metaType ().id () == QMetaType::Int );
363+ QCOMPARE ( arguments.at ( 1 ).toInt (), 404 );
356364}
357365
358366void TestMerginApi::testCreateDeleteProject ()
@@ -485,9 +493,6 @@ void TestMerginApi::testUploadProject()
485493
486494void TestMerginApi::testMultiChunkUploadDownload ()
487495{
488- // this will try to upload a file that needs to be split into multiple chunks
489- // and then also download it correctly again in a clean new download
490-
491496 const QString projectName = " testMultiChunkUploadDownload" ;
492497 const QString projectFullName = CoreUtils::getFullProjectName ( mWorkspaceName , projectName );
493498
@@ -524,8 +529,6 @@ void TestMerginApi::testMultiChunkUploadDownload()
524529
525530void TestMerginApi::testEmptyFileUploadDownload ()
526531{
527- // test will try to upload a project with empty file
528-
529532 const QString projectName = QStringLiteral ( " testEmptyFileUploadDownload" );
530533 const QString projectFullName = CoreUtils::getFullProjectName ( mWorkspaceName , projectName );
531534
@@ -618,9 +621,6 @@ void TestMerginApi::testPushAddedFile()
618621
619622void TestMerginApi::testPushRemovedFile ()
620623{
621- // download a project, then remove a file locally and upload the project.
622- // we then check that the file is really removed on the subsequent download.
623-
624624 const QString projectName = " testPushRemovedFile" ;
625625 const QString projectFullName = CoreUtils::getFullProjectName ( mWorkspaceName , projectName );
626626
@@ -1283,7 +1283,7 @@ void TestMerginApi::testDiffUpdateWithRebase()
12831283 QCOMPARE ( summary, expectedSummary );
12841284
12851285 // update our local version now
1286- downloadRemoteProject ( mApi , mWorkspaceName , projectName );
1286+ downloadRemoteProject ( mApi , projectFullName, projectId );
12871287
12881288 //
12891289 // check the result
@@ -1354,7 +1354,7 @@ void TestMerginApi::testDiffUpdateWithRebaseFailed()
13541354
13551355 // check that projectReloadNeededAfterSync is emitted and has correct argument
13561356 QCOMPARE ( spy.count (), 1 );
1357- QCOMPARE ( spy.takeFirst ().at ( 0 ).toString (), mWorkspaceName + " / " + projectName );
1357+ QCOMPARE ( spy.takeFirst ().at ( 0 ).toString (), projectId );
13581358
13591359 //
13601360 // check the result
@@ -1469,14 +1469,17 @@ void TestMerginApi::testMigrateProject()
14691469
14701470 // migrate project
14711471 QSignalSpy spy ( mApi , &MerginApi::projectCreated );
1472+ QSignalSpy spy1 ( mApi , &MerginApi::projectAttachedToMergin );
14721473 QSignalSpy spy2 ( mApi , &MerginApi::syncProjectFinished );
14731474
1474- QString localProjectId = TestUtils::findProjectByName ( projectFullName, mApi ->mLocalProjects .projects ().values () ).id ();
1475+ // we pass only project name to search for as the project is local and doesn't have workspace set yet
1476+ QString localProjectId = TestUtils::findProjectByName ( projectName, mApi ->mLocalProjects .projects ().values () ).id ();
14751477 mApi ->createProject ( mWorkspaceName , projectName, localProjectId );
14761478
14771479 QVERIFY ( spy.wait ( TestUtils::LONG_REPLY ) );
1478- QCOMPARE ( spy.count (), 1 );
1480+ QCOMPARE ( spy.count (), 2 );
14791481 QCOMPARE ( spy.takeFirst ().at ( 1 ).toBool (), true );
1482+ QVERIFY ( spy1.wait ( TestUtils::LONG_REPLY ) );
14801483 QCOMPARE ( mApi ->transactions ().count (), 1 );
14811484 QVERIFY ( spy2.wait ( TestUtils::LONG_REPLY * 5 ) );
14821485
@@ -1507,16 +1510,18 @@ void TestMerginApi::testMigrateProjectAndSync()
15071510 // step 1
15081511 createLocalProject ( projectDir );
15091512 mApi ->mLocalProjects .reloadDataDir ();
1510- QString localProjectId = TestUtils::findProjectByName ( projectFullName , mApi ->mLocalProjects .projects ().values () ).id ();
1513+ QString localProjectId = TestUtils::findProjectByName ( projectName , mApi ->mLocalProjects .projects ().values () ).id ();
15111514 // step 2
15121515 QSignalSpy spy ( mApi , &MerginApi::projectCreated );
1516+ QSignalSpy spy1 ( mApi , &MerginApi::projectAttachedToMergin );
15131517 QSignalSpy spy2 ( mApi , &MerginApi::syncProjectFinished );
15141518
15151519 mApi ->createProject ( mWorkspaceName , projectName, localProjectId );
15161520
15171521 QVERIFY ( spy.wait ( TestUtils::LONG_REPLY ) );
1518- QCOMPARE ( spy.count (), 1 );
1522+ QCOMPARE ( spy.count (), 2 );
15191523 QCOMPARE ( spy.takeFirst ().at ( 1 ).toBool (), true );
1524+ QVERIFY ( spy1.wait ( TestUtils::LONG_REPLY ) );
15201525 QCOMPARE ( mApi ->transactions ().count (), 1 );
15211526 QVERIFY ( spy2.wait ( TestUtils::LONG_REPLY * 5 ) );
15221527
@@ -1568,17 +1573,19 @@ void TestMerginApi::testMigrateDetachProject()
15681573
15691574 // reload local manager after copying the project
15701575 mApi ->mLocalProjects .reloadDataDir ();
1571- QString localProjectId = TestUtils::findProjectByName ( projectFullName , mApi ->mLocalProjects .projects ().values () ).id ();
1576+ QString localProjectId = TestUtils::findProjectByName ( projectName , mApi ->mLocalProjects .projects ().values () ).id ();
15721577
15731578 // migrate project
15741579 QSignalSpy spy ( mApi , &MerginApi::projectCreated );
1580+ QSignalSpy spy1 ( mApi , &MerginApi::projectAttachedToMergin );
15751581 QSignalSpy spy2 ( mApi , &MerginApi::syncProjectFinished );
15761582
15771583 mApi ->createProject ( mWorkspaceName , projectName, localProjectId );
15781584
15791585 QVERIFY ( spy.wait ( TestUtils::LONG_REPLY ) );
1580- QCOMPARE ( spy.count (), 1 );
1586+ QCOMPARE ( spy.count (), 2 );
15811587 QCOMPARE ( spy.takeFirst ().at ( 1 ).toBool (), true );
1588+ QVERIFY ( spy1.wait ( TestUtils::LONG_REPLY ) );
15821589 QCOMPARE ( mApi ->transactions ().count (), 1 );
15831590 QVERIFY ( spy2.wait ( TestUtils::LONG_REPLY * 5 ) );
15841591
0 commit comments