Skip to content

Commit

Permalink
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
tests and removing truncate
Browse files Browse the repository at this point in the history
VitorVieiraZ committed Jan 13, 2025

Verified

This commit was signed with the committer’s verified signature.
cosmicBboy Niels Bantilan
1 parent 4a6deda commit e0f23b2
Showing 4 changed files with 50 additions and 8 deletions.
28 changes: 28 additions & 0 deletions app/test/testmerginapi.cpp
Original file line number Diff line number Diff line change
@@ -2942,3 +2942,31 @@ void TestMerginApi::testParseVersion()
QCOMPARE( major, 2024 );
QCOMPARE( minor, 4 );
}

void TestMerginApi::testUpdateProjectMetadataRole()
{
QString projectName = "testUpdateProjectMetadataRole";

createRemoteProject( mApiExtra, mWorkspaceName, projectName, mTestDataPath + "/" + TEST_PROJECT_NAME + "/" );
downloadRemoteProject( mApi, mWorkspaceName, projectName );

LocalProject projectInfo = mApi->localProjectsManager().projectFromMerginName( mWorkspaceName, projectName );
QVERIFY( projectInfo.isValid() );
QString projectDir = projectInfo.projectDir;

// Test 1: Initial role should be 'owner'
QString cachedRole = mApi->getCachedProjectRole( MerginApi::getFullProjectName( mWorkspaceName, projectName ) );
QCOMPARE( cachedRole, QString( "owner" ) );

// Test 2: Update cached role to 'reader'
QString newRole = "reader";
bool updateSuccess = mApi->updateCachedProjectRole( MerginApi::getFullProjectName( mWorkspaceName, projectName ), newRole );
QVERIFY( updateSuccess );

// Verify role was updated in cache
cachedRole = mApi->getCachedProjectRole( MerginApi::getFullProjectName( mWorkspaceName, projectName ) );
QCOMPARE( cachedRole, newRole );

// Clean up
deleteRemoteProjectNow( mApi, mWorkspaceName, projectName );
}
1 change: 1 addition & 0 deletions app/test/testmerginapi.h
Original file line number Diff line number Diff line change
@@ -79,6 +79,7 @@ class TestMerginApi: public QObject
void testSynchronizationViaManager();
void testAutosync();
void testAutosyncFailure();
void testUpdateProjectMetadataRole();

void testRegisterAndDelete();
void testCreateWorkspace();
24 changes: 18 additions & 6 deletions core/merginapi.cpp
Original file line number Diff line number Diff line change
@@ -3478,7 +3478,7 @@ bool MerginApi::updateCachedProjectRole( const QString &projectFullName, const Q
obj["role"] = newRole;
doc.setObject( obj );

if ( !file.open( QIODevice::WriteOnly | QIODevice::Truncate ) )
if ( !file.open( QIODevice::WriteOnly ) )
{
return false;
}
@@ -3991,9 +3991,7 @@ void MerginApi::updateProjectMetadataRole( const QString &projectFullName )
return;
}

QString projectDir = mLocalProjects.projectFromMerginName( projectFullName ).projectDir;
MerginProjectMetadata cachedProjectMetadata = MerginProjectMetadata::fromCachedJson( projectDir + "/" + sMetadataFile );
QString cachedRole = cachedProjectMetadata.role;
QString cachedRole = MerginApi::getCachedProjectRole( projectFullName );

QNetworkReply *reply = getProjectInfo( projectFullName );
if ( !reply )
@@ -4003,7 +4001,6 @@ void MerginApi::updateProjectMetadataRole( const QString &projectFullName )
}

reply->request().setAttribute( static_cast<QNetworkRequest::Attribute>( AttrProjectFullName ), projectFullName );
reply->request().setAttribute( static_cast<QNetworkRequest::Attribute>( AttrCachedRole ), cachedRole );
connect( reply, &QNetworkReply::finished, this, &MerginApi::updateProjectMetadataRoleReplyFinished );
}

@@ -4013,7 +4010,7 @@ void MerginApi::updateProjectMetadataRoleReplyFinished()
Q_ASSERT( r );

QString projectFullName = r->request().attribute( static_cast<QNetworkRequest::Attribute>( AttrProjectFullName ) ).toString();
QString cachedRole = r->request().attribute( static_cast<QNetworkRequest::Attribute>( AttrCachedRole ) ).toString();
QString cachedRole = MerginApi::getCachedProjectRole( projectFullName );

if ( r->error() == QNetworkReply::NoError )
{
@@ -4040,3 +4037,18 @@ void MerginApi::updateProjectMetadataRoleReplyFinished()

r->deleteLater();
}

QString MerginApi::getCachedProjectRole( const QString &projectFullName ) const
{
if ( projectFullName.isEmpty() )
return QString();

QString projectDir = mLocalProjects.projectFromMerginName( projectFullName ).projectDir;

if ( projectDir.isEmpty() )
return QString();

MerginProjectMetadata cachedProjectMetadata = MerginProjectMetadata::fromCachedJson( projectDir + "/" + sMetadataFile );

return cachedProjectMetadata.role;
}
5 changes: 3 additions & 2 deletions core/merginapi.h
Original file line number Diff line number Diff line change
@@ -799,6 +799,8 @@ class MerginApi: public QObject

bool updateCachedProjectRole( const QString &projectFullName, const QString &newRole );

QString getCachedProjectRole( const QString &projectFullName ) const;

QNetworkAccessManager mManager;
QString mApiRoot;
LocalProjectsManager &mLocalProjects;
@@ -814,8 +816,7 @@ class MerginApi: public QObject
AttrProjectFullName = QNetworkRequest::User,
AttrTempFileName = QNetworkRequest::User + 1,
AttrWorkspaceName = QNetworkRequest::User + 2,
AttrAcceptFlag = QNetworkRequest::User + 3,
AttrCachedRole = QNetworkRequest::User + 4
AttrAcceptFlag = QNetworkRequest::User + 3
};

Transactions mTransactionalStatus; //projectFullname -> transactionStatus

1 comment on commit e0f23b2

@inputapp-bot
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

iOS - version 25.1.698111 just submitted!

Please sign in to comment.