Skip to content
Browse files

Parsovani dat z apiary.apib do ngMockE2E

  • Loading branch information...
1 parent 4d39c7b commit e5aa672e01f2fa7296ff646babe7cd23a0549e02 @JakubMrozek committed Dec 3, 2012
Showing with 27 additions and 9 deletions.
  1. +1 −1 grunt.js
  2. +4 −0 public/index.html
  3. +1 −0 public/js/apiary.js
  4. +19 −2 public/js/services.js
  5. +2 −6 test/frontend/e2e/scenarios.js
View
2 grunt.js
@@ -28,7 +28,7 @@ module.exports = function (grunt) {
var content = grunt.file.read('apiary.apib');
var blueprint = parser.parse(content);
var json = JSON.stringify(blueprint.sections);
- grunt.file.write('test/frontend/apiary.js', "var apiary = " + json);
+ grunt.file.write('public/js/apiary.js', "var apiary = " + json);
});
};
View
4 public/index.html
@@ -37,6 +37,10 @@
<script src="/js/directives.js"></script>
<script src="/lib/angular/angular-resource.js"></script>
<!-- todo -->
+
<script src="/lib/angular/angular-mocks.js"></script>
+ <script src="/js/apiary.js"></script>
+
+ <!-- /todo -->
</body>
</html>
View
1 public/js/apiary.js
@@ -0,0 +1 @@
+var apiary = [{"name":"Stranky","description":"","resources":[{"description":"Vrácení seznamu všech stránek.","method":"GET","url":"/pages","request":{"headers":{},"body":""},"responses":[{"status":200,"headers":{"Content-Type":"application/json"},"body":"[\n{\"id\":\"5098eaef0496600200000001\",\n\"content\":\"Lorem ipsum set dolorem\",\n\"title\":\"Kontakt\",\n\"url\":\"kontakt\"},\n{\"id\":\"5098eaef0496600200000002\",\n\"content\":\"Lorem ipsum set dolorem\",\n\"title\":\"Obchodní podmínky\",\n\"url\":\"obchodni-podminky\"},\n{\"id\":\"5098eaef0496600200000003\",\n\"content\":\"Lorem ipsum set dolorem\",\n\"title\":\"Doprava a platba\",\n\"url\":\"doprava a platba\"}\n]"}]},{"description":"Zobrazení detailu jedné stránky.","method":"GET","url":"/pages/{id}","request":{"headers":{},"body":""},"responses":[{"status":200,"headers":{"Content-Type":"application/json"},"body":"{\"id\":\"5098eaef0496600200000001\",\n\"content\":\"Lorem ipsum set dolorem\",\n\"title\":\"Kontakt\",\n\"url\":\"kontakt\"}"}]},{"description":"Vložení nové stránky do databáze.","method":"POST","url":"/pages","request":{"headers":{"Content-Type":"application/json"},"body":"{\"content\":\"Lorem ipsum set dolorem\", \"title\":\"Nákupní řád\"}"},"responses":[{"status":201,"headers":{"Location":"//api/v1/pages/nakupni-rad"},"body":""}]},{"description":"Editace jedné stránky v databázi.","method":"PUT","url":"/pages/{id}","request":{"headers":{"Content-Type":"application/json"},"body":"{\"content\":\"Lorem ipsum set dolorem\", \n\"title\":\"Nákupní řád e-shopu\"}"},"responses":[{"status":200,"headers":{"Content-Type":"application/json"},"body":"{\"content\":\"Lorem ipsum set dolorem\",\n\"title\":\"Nákupní řád e-shopu\"}"}]},{"description":"Smazání stránky z databáze.","method":"DELETE","url":"/pages/{id}","request":{"headers":{},"body":""},"responses":[{"status":204,"headers":{},"body":""}]}]}]
View
21 public/js/services.js
@@ -17,8 +17,25 @@ angular.module('zdrojakServices', ['ngResource'])
/** Mock http */
var mock = angular.module('zdrojakMock', ['ngMockE2E']);
mock.run(function($httpBackend) {
- var phones = [{name: 'phone1'}, {name: 'phone2'}];
- $httpBackend.whenGET('/api/v1/pages').respond(phones);
+
+ var resources = apiary[0].resources;
+ resources.forEach(function(res){
+ var url = '/api/v1' + res.url.replace('{id}', ':id');
+ switch (res.method) {
+ case 'GET':
+ $httpBackend.whenGET(url).respond(res.responses[0].body);
+ break;
+ case 'POST':
+ $httpBackend.whenPOST(url).respond(res.responses[0].body);
+ break;
+ case 'PUT':
+ $httpBackend.whenPUT(url).respond(res.responses[0].body);
+ break;
+ case 'DELETE':
+ $httpBackend.whenDELETE(url).respond(res.responses[0].body);
+ break;
+ }
+ });
//nechat projit pozadavky na sablony
$httpBackend.whenGET(/^\/partials\//).passThrough();
View
8 test/frontend/e2e/scenarios.js
@@ -7,18 +7,14 @@ var scenario = true;
describe('zdrojak', function() {
- beforeEach(function() {
- browser().navigateTo('/');
- });
-
- describe('seznam vsech stranek', function() {
+ describe('/pages', function() {
beforeEach(function() {
browser().navigateTo('/pages');
});
it('zobrazi seznam vsech stranek', function() {
- var repeater = using('.body').repeater('ul li');
+ var repeater = using('#pages-list').repeater('ul li');
expect(repeater.count()).toBe(3);
});

0 comments on commit e5aa672

Please sign in to comment.
Something went wrong with that request. Please try again.