|
| 1 | +<?php |
| 2 | + |
| 3 | +/* |
| 4 | + * This file is auto-generated, do not edit |
| 5 | + */ |
| 6 | + |
| 7 | +namespace Recombee\RecommApi\Tests; |
| 8 | + |
| 9 | +use Recombee\RecommApi\Exceptions as Exc; |
| 10 | + |
| 11 | +abstract class AddRatingTestCase extends RecombeeTestCase { |
| 12 | + |
| 13 | + abstract protected function createRequest($user_id,$item_id,$rating,$optional); |
| 14 | + |
| 15 | + public function testAddRating() { |
| 16 | + |
| 17 | + //it does not fail with cascadeCreate |
| 18 | + $req = $this->createRequest('u_id','i_id',1,['cascadeCreate' => true]); |
| 19 | + $resp = $this->client->send($req); |
| 20 | + |
| 21 | + //it does not fail with existing item and user |
| 22 | + $req = $this->createRequest('entity_id','entity_id',0); |
| 23 | + $resp = $this->client->send($req); |
| 24 | + |
| 25 | + //it fails with nonexisting item id |
| 26 | + $req = $this->createRequest('entity_id','nonex_id',-1); |
| 27 | + try { |
| 28 | + |
| 29 | + $this->client->send($req); |
| 30 | + throw new \Exception('Exception was not thrown'); |
| 31 | + } |
| 32 | + catch(Exc\ResponseException $e) |
| 33 | + { |
| 34 | + $this->assertEquals(404, $e->status_code); |
| 35 | + } |
| 36 | + |
| 37 | + //it fails with nonexisting user id |
| 38 | + $req = $this->createRequest('nonex_id','entity_id',0.5); |
| 39 | + try { |
| 40 | + |
| 41 | + $this->client->send($req); |
| 42 | + throw new \Exception('Exception was not thrown'); |
| 43 | + } |
| 44 | + catch(Exc\ResponseException $e) |
| 45 | + { |
| 46 | + $this->assertEquals(404, $e->status_code); |
| 47 | + } |
| 48 | + |
| 49 | + //it fails with invalid time |
| 50 | + $req = $this->createRequest('entity_id','entity_id',0,['timestamp' => -15]); |
| 51 | + try { |
| 52 | + |
| 53 | + $this->client->send($req); |
| 54 | + throw new \Exception('Exception was not thrown'); |
| 55 | + } |
| 56 | + catch(Exc\ResponseException $e) |
| 57 | + { |
| 58 | + $this->assertEquals(400, $e->status_code); |
| 59 | + } |
| 60 | + |
| 61 | + //it fails with invalid rating |
| 62 | + $req = $this->createRequest('entity_id','entity_id',-2); |
| 63 | + try { |
| 64 | + |
| 65 | + $this->client->send($req); |
| 66 | + throw new \Exception('Exception was not thrown'); |
| 67 | + } |
| 68 | + catch(Exc\ResponseException $e) |
| 69 | + { |
| 70 | + $this->assertEquals(400, $e->status_code); |
| 71 | + } |
| 72 | + |
| 73 | + //it really stores interaction to the system |
| 74 | + $req = $this->createRequest('u_id','i_id',0.3,['cascadeCreate' => true,'timestamp' => 5]); |
| 75 | + $resp = $this->client->send($req); |
| 76 | + try { |
| 77 | + |
| 78 | + $this->client->send($req); |
| 79 | + throw new \Exception('Exception was not thrown'); |
| 80 | + } |
| 81 | + catch(Exc\ResponseException $e) |
| 82 | + { |
| 83 | + $this->assertEquals(409, $e->status_code); |
| 84 | + } |
| 85 | + |
| 86 | + } |
| 87 | +} |
| 88 | + |
| 89 | +?> |
0 commit comments