Skip to content

Commit f340fbc

Browse files
author
Bernhard Posselt
committed
also update content when calling create api route
1 parent 3c41c91 commit f340fbc

File tree

4 files changed

+31
-10
lines changed

4 files changed

+31
-10
lines changed

controller/notescontroller.php

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -79,9 +79,15 @@ public function get($id) {
7979

8080
/**
8181
* @NoAdminRequired
82+
*
83+
* @param string $content
8284
*/
83-
public function create() {
84-
return new DataResponse($this->notesService->create($this->userId));
85+
public function create($content) {
86+
$note = $this->notesService->create($this->userId);
87+
$note = $this->notesService->update(
88+
$note->getId(), $content, $this->userId
89+
);
90+
return new DataResponse($note);
8591
}
8692

8793

phpunit.integration.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
<phpunit bootstrap="../../lib/base.php">
22
<testsuites>
3-
<testsuite name="unit">
3+
<testsuite name="integration">
44
<directory>./tests/integration</directory>
55
</testsuite>
66
</testsuites>

tests/integration/controller/NotesApiControllerTest.php

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -11,21 +11,22 @@
1111

1212
namespace OCA\Notes\Controller;
1313

14+
use PHPUnit_Framework_TestCase;
15+
1416
use OCP\AppFramework\Http\DataResponse;
1517
use OCP\AppFramework\App;
1618
use OCP\Files\File;
17-
use Test\TestCase;
1819

19-
class NotesApiControllerTest extends TestCase {
20+
21+
class NotesApiControllerTest extends PHPUnit_Framework_TestCase {
2022

2123
private $controller;
2224
private $mapper;
2325
private $userId = 'test';
26+
private $notesFolder = '/test/notes';
2427
private $fs;
2528

2629
public function setUp() {
27-
parent::setUp();
28-
2930
$app = new App('notes');
3031
$container = $app->getContainer();
3132
$container->registerService('UserId', function($c) {
@@ -38,6 +39,7 @@ public function setUp() {
3839
$this->fs = $this->controller = $container->query(
3940
'OCP\Files\IRootFolder'
4041
);
42+
$this->fs->newFolder();
4143
}
4244

4345

@@ -54,10 +56,15 @@ public function testUpdate() {
5456
$this->assertCount(1, $notes);
5557
$this->assertEquals('test2', $notes[0]->getContent());
5658

57-
$file = $this->fs->get('/' . $userId . '/notes/test2.txt');
59+
$file = $this->fs->get($this->notesFolder . '/test2.txt');
5860

5961
$this->assertTrue($file instanceof File);
6062
}
6163

6264

65+
public function tearDown() {
66+
$this->fs->get($this->notesFolder)->delete();
67+
}
68+
69+
6370
}

tests/unit/controller/NotesControllerTest.php

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
use OCP\AppFramework\Http;
1919

2020
use OCA\Notes\Service\NoteDoesNotExistException;
21+
use OCA\Notes\Db\Note;
2122

2223

2324
class NotesControllerTest extends PHPUnit_Framework_TestCase {
@@ -157,14 +158,21 @@ public function testSetConfig(){
157158
* POST /notes
158159
*/
159160
public function testCreate(){
160-
$expected = ['hi'];
161+
$created = new Note();
162+
$created->setId(3);
163+
164+
$expected = new Note();
161165

162166
$this->service->expects($this->once())
163167
->method('create')
164168
->with($this->equalTo($this->userId))
169+
->will($this->returnValue($created));
170+
$this->service->expects($this->once())
171+
->method('update')
172+
->with(3, 'hi', $this->userId)
165173
->will($this->returnValue($expected));
166174

167-
$response = $this->controller->create();
175+
$response = $this->controller->create('hi');
168176

169177
$this->assertEquals($expected, $response->getData());
170178
$this->assertTrue($response instanceof DataResponse);

0 commit comments

Comments
 (0)