Skip to content

Commit

Permalink
chore: add file conversion integration tests
Browse files Browse the repository at this point in the history
Signed-off-by: skjnldsv <[email protected]>
  • Loading branch information
skjnldsv committed Jan 16, 2025
1 parent 55337af commit 4271705
Show file tree
Hide file tree
Showing 5 changed files with 72 additions and 0 deletions.
2 changes: 2 additions & 0 deletions build/integration/config/behat.yml
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,8 @@ default:
baseUrl: http://localhost:8080
- ChecksumsContext:
baseUrl: http://localhost:8080
- ConversionsContext:
baseUrl: http://localhost:8080
- CommandLineContext:
baseUrl: http://localhost:8080
ocPath: ../../
Expand Down
Binary file added build/integration/data/clouds.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
2 changes: 2 additions & 0 deletions build/integration/data/clouds.jpg.license
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
SPDX-FileCopyrightText: 2019 CHUTTERSNAP <https://unsplash.com/@chuttersnap> <https://unsplash.com/photos/blue-clouds-under-white-sky-9AqIdzEc9pY>"
SPDX-License-Identifier: LicenseRef-Unsplash
52 changes: 52 additions & 0 deletions build/integration/features/bootstrap/ConversionsContext.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
<?php
/**
* SPDX-FileCopyrightText: 2016-2024 Nextcloud GmbH and Nextcloud contributors
* SPDX-FileCopyrightText: 2016 ownCloud, Inc.
* SPDX-License-Identifier: AGPL-3.0-or-later
*/
require __DIR__ . '/../../vendor/autoload.php';

use Behat\Behat\Context\Context;
use Behat\Behat\Context\SnippetAcceptingContext;
use Behat\Gherkin\Node\TableNode;
use GuzzleHttp\Client;

class ConversionsContext implements Context, SnippetAcceptingContext {
use WebDav;

public function __construct(string $baseUrl) {
$this->baseUrl = $baseUrl;

// in case of ci deployment we take the server url from the environment
$testServerUrl = getenv('TEST_SERVER_URL');
if ($testServerUrl !== false) {
$this->baseUrl = substr($testServerUrl, 0, -5);
}
}

/** @BeforeScenario */
public function setUpScenario() {
$this->client = new Client();
}

/** @AfterScenario */
public function tearDownScenario() {
}

/**
* @When /^user "([^"]*)" converts file "([^"]*)" to "([^"]*)"$/
*/
public function userConvertsTheSavedFileId(string $user, string $path, string $mime) {
$this->userConvertsTheSavedFileIdTo($user, $path, $mime, null);

}

/**
* @When /^user "([^"]*)" converts file "([^"]*)" to "([^"]*)" as "([^"]*)"$/
*/
public function userConvertsTheSavedFileIdTo(string $user, string $path, string $mime, ?string $destination) {
$fileId = $this->getFileIdForPath($user, $path);
$body = new TableNode([['fileId', $fileId], ['mime', $mime], ['destination', $destination]]);
$this->sendingToWith('post', "/ocs/v2.php/apps/files/api/v1/convert", $body);
}
}
16 changes: 16 additions & 0 deletions build/integration/files_features/conversions.feature
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
# SPDX-FileCopyrightText: 2025 Nextcloud GmbH and Nextcloud contributors
# SPDX-License-Identifier: AGPL-3.0-only

Feature: conversions
Background:
Given using api version "1"
Given using new dav path
Given user "user0" exists

Scenario: Converting a file works
Given user "user0" uploads file "data/clouds.jpg" to "/clouds.jpg"
Then as "user0" the file "/clouds.jpg" exists
When user "user0" converts file "/clouds.jpg" to "image/png"
Then the HTTP status code should be "200"
Then the OCS status code should be "200"
Then as "user0" the file "/clouds.png" exists

0 comments on commit 4271705

Please sign in to comment.