Skip to content

Commit

Permalink
AppGroup membership testcase 3x (apigee#304)
Browse files Browse the repository at this point in the history
  • Loading branch information
shishir-intelli authored Aug 25, 2023
1 parent f135fa1 commit 6c54545
Show file tree
Hide file tree
Showing 6 changed files with 143 additions and 3 deletions.
4 changes: 2 additions & 2 deletions src/Api/ApigeeX/Structure/AppGroupMembership.php
Original file line number Diff line number Diff line change
Expand Up @@ -112,10 +112,10 @@ public function isMember(string $email): bool
* @param string $email
* Developer email address.
*
* @return string|null
* @return array|null
* Developer role if set, NULL otherwise.
*/
public function getRole(string $email): ?string
public function getRole(string $email): ?array
{
return $this->members[$email] ?? null;
}
Expand Down
1 change: 1 addition & 0 deletions tests/Api/ApigeeX/Controller/AppControllerTestBase.php
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,7 @@ protected function alterArraysBeforeCompareSentAndReceivedPayloadsInCreate(array
*/
protected function alterObjectsBeforeCompareResponseAndCreatedEntity(\stdClass &$responseObject, EntityInterface $created): void
{
/* @var \Apigee\Edge\Api\Management\Entity\DeveloperAppInterface $created */
$responseObject->apiProducts = $created->getApiProducts();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@ public static function setUpBeforeClass(): void
{
parent::setUpBeforeClass();
static::$testApiProduct = static::getNewApiProduct();
static::apiProductController(static::defaultAPIClient())->create(static::$testApiProduct);
static::$testAppOwner = static::setupTestAppOwner();
static::$testApp = static::setupTestApp(static::setupTestAppOwner());
}
Expand Down Expand Up @@ -125,7 +126,6 @@ public function testLoad(AppCredentialInterface $created)
*/
public function testAddProducts(string $entityId): void
{
static::apiProductController(static::defaultAPIClient())->create(static::$testApiProduct);
/** @var \Apigee\Edge\Api\Management\Controller\AppCredentialControllerInterface $controller */
$controller = $this->entityController();
$credential = $controller->addProducts($entityId, [static::$testApiProduct->id()]);
Expand Down
131 changes: 131 additions & 0 deletions tests/Api/ApigeeX/Controller/AppGroupMembersControllerTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,131 @@
<?php

/*
* Copyright 2023 Google LLC
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* https://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

namespace Apigee\Edge\Tests\Api\ApigeeX\Controller;

use Apigee\Edge\Api\ApigeeX\Controller\AppGroupMembersController;
use Apigee\Edge\Api\ApigeeX\Controller\AppGroupMembersControllerInterface;
use Apigee\Edge\Api\ApigeeX\Structure\AppGroupMembership;
use Apigee\Edge\ClientInterface;
use Apigee\Edge\Tests\Api\ApigeeX\Entity\AppGroupTestEntityProviderTrait;
use Apigee\Edge\Tests\Api\Management\Controller\DeveloperControllerAwareTestTrait;
use Apigee\Edge\Tests\Api\Management\Entity\DeveloperTestEntityProviderTrait;
use Apigee\Edge\Tests\Test\Controller\ControllerTestBase;
use Apigee\Edge\Tests\Test\Controller\DefaultAPIClientAwareTrait;
use Apigee\Edge\Tests\Test\TestClientFactory;
use Apigee\Edge\Tests\Test\Utility\EntityStorage;
use Apigee\Edge\Tests\Test\Utility\MarkOnlineTestSkippedAwareTrait;

/**
* Class AppGroupMembersControllerTest.
*
* @group controller
* @group management
*/
class AppGroupMembersControllerTest extends ControllerTestBase
{
use DefaultAPIClientAwareTrait;
use AppGroupControllerAwareTestTrait;
use DeveloperControllerAwareTestTrait;
use AppGroupTestEntityProviderTrait;
use DeveloperTestEntityProviderTrait;
use MarkOnlineTestSkippedAwareTrait;

protected const TEST_ROLE = 'simple member';

/** @var \Apigee\Edge\Api\ApigeeX\Entity\AppGroupInterface */
protected static $testAppGroup;

/** @var \Apigee\Edge\Api\Management\Entity\DeveloperInterface */
protected static $testDeveloper1;

/** @var \Apigee\Edge\Api\Management\Entity\DeveloperInterface */
protected static $testDeveloper2;

/**
* {@inheritdoc}
*/
public static function setUpBeforeClass(): void
{
parent::setUpBeforeClass();
static::$testAppGroup = static::getNewAppGroup();
static::appGroupController()->create(static::$testAppGroup);
static::$testDeveloper1 = static::getNewDeveloper();
static::developerController()->create(static::$testDeveloper1);
static::$testDeveloper2 = static::getNewDeveloper();
static::developerController()->create(static::$testDeveloper2);
}

/**
* {@inheritdoc}
*/
public static function tearDownAfterClass(): void
{
parent::tearDownAfterClass();
EntityStorage::getInstance()->purgeCreatedEntities();
}

public function testCreateMembership(): void
{
$members = $this->getAppGroupMembershipController()->setMembers(new AppGroupMembership([static::$testDeveloper1->getEmail() => static::TEST_ROLE]));
$this->assertTrue($members->isMember(static::$testDeveloper1->getEmail()));
$this->assertContains(static::TEST_ROLE, $members->getRole(static::$testDeveloper1->getEmail()));
}

/**
* @depends testCreateMembership
*
* @group online
*/
public function testUpdateMembership(): void
{
static::markOnlineTestSkipped(__FUNCTION__);
$role = 'not a simple member';
$members = $this->getAppGroupMembershipController()->setMembers(new AppGroupMembership([static::$testDeveloper1->getEmail() => $role]));
$this->assertTrue($members->isMember(static::$testDeveloper1->getEmail()));
$this->assertEquals($role, $members->getRole(static::$testDeveloper1->getEmail()));
}

/**
* To make sure AppGroup has no members.
*
* @group online
*/
public function testAddMember(): void
{
$this->getAppGroupMembershipController()->setMembers(new AppGroupMembership([static::$testDeveloper1->getEmail() => '']));
// Add a new member.
$this->getAppGroupMembershipController()->setMembers(new AppGroupMembership([static::$testDeveloper2->getEmail() => '']));
$members = $this->getAppGroupMembershipController()->getMembers();
$this->assertTrue($members->isMember(static::$testDeveloper1->getEmail()));
$this->assertTrue($members->isMember(static::$testDeveloper2->getEmail()));
}

/**
* {@inheritdoc}
*/
protected static function defaultAPIClient(): ClientInterface
{
return TestClientFactory::getClient();
}

protected function getAppGroupMembershipController(): AppGroupMembersControllerInterface
{
return new AppGroupMembersController(static::$testAppGroup->id(), static::defaultTestOrganization(static::defaultAPIClient()), static::defaultAPIClient());
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,10 @@
{
"name": "foo",
"value": "bar"
},
{
"name": "__apigee_reserved__developer_details",
"value": "[{\"developer\":\"[email protected]\",\"roles\":[\"admin\"]}, {\"developer\":\"[email protected]\",\"roles\":[\"admin\"]}]"
}
],
"createdAt": 1691588699000,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,10 @@
{
"name": "bar",
"value": "baz"
},
{
"name": "__apigee_reserved__developer_details",
"value": "[{\"developer\":\"[email protected]\",\"roles\":[\"simple member\"]}]"
}
],
"createdAt": 1691588699000,
Expand Down

0 comments on commit 6c54545

Please sign in to comment.