Skip to content

Commit

Permalink
Tweak tests.
Browse files Browse the repository at this point in the history
  • Loading branch information
ndouglas committed Oct 4, 2023
1 parent 4caa98a commit 0caf65c
Show file tree
Hide file tree
Showing 3 changed files with 56 additions and 19 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,25 @@ public function __construct(
$this->frontendVersion = $frontendVersion;
}

/**
* Get the frontend.
*
* @param string $frontend
* The frontend whose version we are getting.
*
* @return \Drupal\va_gov_content_release\Frontend\Frontend
* The frontend.
*/
public function getFrontend(string $frontend) {
try {
return Frontend::from($frontend);
}
catch (\Throwable $exception) {
$this->io()->error($exception->getMessage());
exit(1);
}
}

/**
* Get the frontend version.
*
Expand All @@ -40,7 +59,7 @@ public function __construct(
* @aliases va-gov-content-release-frontend-version-get
*/
public function get(string $frontend = 'content_build') {
$frontend = Frontend::fromRawValue($frontend);
$frontend = $this->getFrontend($frontend);
$value = $this->frontendVersion->getVersion($frontend);
$this->io()->write($value);
}
Expand All @@ -55,7 +74,7 @@ public function get(string $frontend = 'content_build') {
* @aliases va-gov-content-release-frontend-version-reset
*/
public function reset(string $frontend = 'content_build') {
$frontend = Frontend::fromRawValue($frontend);
$frontend = $this->getFrontend($frontend);
$this->frontendVersion->resetVersion($frontend);
$this->io()->success('Frontend version reset.');
}
Expand All @@ -72,7 +91,7 @@ public function reset(string $frontend = 'content_build') {
* @aliases va-gov-content-release-frontend-version-set
*/
public function setVersion(string $frontend = 'content_build', $version = '_default') {
$frontend = Frontend::fromRawValue($frontend);
$frontend = $this->getFrontend($frontend);
$this->frontendVersion->setVersion($frontend, $version);
$this->io()->success('Frontend version set to ' . $version);
}
Expand Down
34 changes: 25 additions & 9 deletions scripts/build-frontend.sh
Original file line number Diff line number Diff line change
Expand Up @@ -55,25 +55,41 @@ rm -rf ${reporoot}/docroot/vendor/va-gov
composer install --no-scripts &>> ${logfile}

# Get the requested frontend version
feversion=$(drush va-gov:content-release:get-frontend-version | tail -1)
feversion=$(drush va-gov-content-release:frontend-version:get content_build | tail -1)
if [ "${feversion}" != "__default" ]; then
echo "==> Checking out the requested frontend version" >> ${logfile}
pushd ${reporoot}/docroot/vendor/va-gov/content-build
if echo "$feversion" | grep -qE '^[0-9]+$' > /dev/null; then
echo "==> Checking out PR #${feversion}"
git fetch origin pull/${feversion}/head &>> ${logfile}
else
echo "==> Checking out git ref ${feversion}"
git fetch origin ${feversion} &>> ${logfile}
fi
git checkout FETCH_HEAD &>> ${logfile}
if echo "$feversion" | grep -qE '^[0-9]+$' > /dev/null; then
echo "==> Checking out PR #${feversion}"
git fetch origin pull/${feversion}/head &>> ${logfile}
else
echo "==> Checking out git ref ${feversion}"
git fetch origin ${feversion} &>> ${logfile}
fi
git checkout FETCH_HEAD &>> ${logfile}
popd
fi

# Install 3rd party deps.
echo "==> Installing yarn dependencies" >> ${logfile}
composer va:web:install &>> ${logfile}

# Get the requested vets-website version
vwversion=$(drush va-gov-content-release:vets-website-version:get vets_website | tail -1)
if [ "${vwversion}" != "__default" ]; then
echo "==> Checking out the requested vets-website version" >> ${logfile}
pushd ${reporoot}/docroot/vendor/va-gov/vets-website
if echo "$vwversion" | grep -qE '^[0-9]+$' > /dev/null; then
echo "==> Checking out PR #${vwversion}"
git fetch origin pull/${vwversion}/head &>> ${logfile}
else
echo "==> Checking out git ref ${vwversion}"
git fetch origin ${vwversion} &>> ${logfile}
fi
git checkout FETCH_HEAD &>> ${logfile}
popd
fi

# Run the build.
echo "==> Starting build" >> ${logfile}
drush va-gov:content-release:advance-state inprogress
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,9 @@

namespace tests\phpunit\va_gov_content_release\unit\FrontendVersion;

use Drupal\Core\State\State;
use Drupal\Core\KeyValueStore\KeyValueMemoryFactory;
use Drupal\Core\State\State;
use Drupal\va_gov_content_release\Frontend\Frontend;
use Drupal\va_gov_content_release\FrontendVersion\FrontendVersion;
use Drupal\va_gov_content_release\FrontendVersion\FrontendVersionInterface;
use Tests\Support\Classes\VaGovUnitTestBase;
Expand All @@ -22,18 +23,19 @@ class FrontendVersionTest extends VaGovUnitTestBase {
* Test that the service works as expected.
*
* @covers ::__construct
* @covers ::get
* @covers ::set
* @covers ::reset
* @covers ::getVersion
* @covers ::setVersion
* @covers ::resetVersion
*/
public function testGetSetReset() : void {
$state = new State(new KeyValueMemoryFactory());
$frontend = Frontend::ContentBuild;
$frontendVersion = new FrontendVersion($state);
$this->assertEquals(FrontendVersionInterface::FRONTEND_VERSION_DEFAULT, $frontendVersion->get());
$this->assertEquals(FrontendVersionInterface::FRONTEND_VERSION_DEFAULT, $frontendVersion->getVersion($frontend));
$frontendVersion->set('1.2.3');
$this->assertEquals('1.2.3', $frontendVersion->get());
$this->assertEquals('1.2.3', $frontendVersion->getVersion($frontend));
$frontendVersion->reset();
$this->assertEquals(FrontendVersionInterface::FRONTEND_VERSION_DEFAULT, $frontendVersion->get());
$this->assertEquals(FrontendVersionInterface::FRONTEND_VERSION_DEFAULT, $frontendVersion->getVersion($frontend));
}

}

0 comments on commit 0caf65c

Please sign in to comment.