From b0e30a5c3212b1baff5a113659290161260ff63e Mon Sep 17 00:00:00 2001 From: Vitaliy Makeev Date: Mon, 1 Jun 2015 16:37:25 +0500 Subject: [PATCH] =?UTF-8?q?=D0=A7=D0=B0=D1=81=D1=82=D0=B8=D1=87=D0=BD?= =?UTF-8?q?=D0=BE=D0=B5=20=D0=BF=D0=BE=D0=BA=D1=80=D1=8B=D1=82=D0=B8=D0=B5?= =?UTF-8?q?=20=D1=82=D0=B5=D1=81=D1=82=D0=B0=D0=BC=D0=B8=20#12?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- test/init.js | 16 ++ test/mocha.opts | 3 + .../res/html/server-responce-503.html | 0 {tests => test}/res/mappings/inheritance.json | 0 .../xml/entities/collection/goodFolder.xml | 0 .../res/xml/entities/collection/uuid.xml | 0 {tests => test}/res/xml/entities/error/01.xml | 0 .../f607654a-e293-4b64-b8b1-14503542cd89.xml | 0 test/specs/client.js | 171 ++++++++++++++++++ test/specs/model.js | 121 +++++++++++++ test/specs/moysklad.js | 20 ++ test/specs/tools.js | 163 +++++++++++++++++ tests/specs/client.js | 40 ---- tests/specs/lazy-loader.js | 7 - tests/specs/moysklad-client.js | 17 -- tests/specs/simple-test.js | 16 -- 16 files changed, 494 insertions(+), 80 deletions(-) create mode 100644 test/init.js create mode 100644 test/mocha.opts rename {tests => test}/res/html/server-responce-503.html (100%) rename {tests => test}/res/mappings/inheritance.json (100%) rename {tests => test}/res/xml/entities/collection/goodFolder.xml (100%) rename {tests => test}/res/xml/entities/collection/uuid.xml (100%) rename {tests => test}/res/xml/entities/error/01.xml (100%) rename {tests => test}/res/xml/entities/good/f607654a-e293-4b64-b8b1-14503542cd89.xml (100%) create mode 100644 test/specs/client.js create mode 100644 test/specs/model.js create mode 100644 test/specs/moysklad.js create mode 100644 test/specs/tools.js delete mode 100644 tests/specs/client.js delete mode 100644 tests/specs/lazy-loader.js delete mode 100644 tests/specs/moysklad-client.js delete mode 100644 tests/specs/simple-test.js diff --git a/test/init.js b/test/init.js new file mode 100644 index 0000000..39a8c7f --- /dev/null +++ b/test/init.js @@ -0,0 +1,16 @@ +/** + * init.js + * Date: 26.05.15 + * Vitaliy V. Makeev (w.makeev@gmail.com) + */ + +var chai = require('chai'); + +//global.chai = require('chai'); +global._ = require('lodash'); +global.expect = chai.expect; +global.assert = chai.assert; + +global.moysklad = require('../src/moysklad-client/index.js'); + +chai.should(); diff --git a/test/mocha.opts b/test/mocha.opts new file mode 100644 index 0000000..80568fe --- /dev/null +++ b/test/mocha.opts @@ -0,0 +1,3 @@ +--reporter spec +test/init.js +test/specs/*.js \ No newline at end of file diff --git a/tests/res/html/server-responce-503.html b/test/res/html/server-responce-503.html similarity index 100% rename from tests/res/html/server-responce-503.html rename to test/res/html/server-responce-503.html diff --git a/tests/res/mappings/inheritance.json b/test/res/mappings/inheritance.json similarity index 100% rename from tests/res/mappings/inheritance.json rename to test/res/mappings/inheritance.json diff --git a/tests/res/xml/entities/collection/goodFolder.xml b/test/res/xml/entities/collection/goodFolder.xml similarity index 100% rename from tests/res/xml/entities/collection/goodFolder.xml rename to test/res/xml/entities/collection/goodFolder.xml diff --git a/tests/res/xml/entities/collection/uuid.xml b/test/res/xml/entities/collection/uuid.xml similarity index 100% rename from tests/res/xml/entities/collection/uuid.xml rename to test/res/xml/entities/collection/uuid.xml diff --git a/tests/res/xml/entities/error/01.xml b/test/res/xml/entities/error/01.xml similarity index 100% rename from tests/res/xml/entities/error/01.xml rename to test/res/xml/entities/error/01.xml diff --git a/tests/res/xml/entities/good/f607654a-e293-4b64-b8b1-14503542cd89.xml b/test/res/xml/entities/good/f607654a-e293-4b64-b8b1-14503542cd89.xml similarity index 100% rename from tests/res/xml/entities/good/f607654a-e293-4b64-b8b1-14503542cd89.xml rename to test/res/xml/entities/good/f607654a-e293-4b64-b8b1-14503542cd89.xml diff --git a/test/specs/client.js b/test/specs/client.js new file mode 100644 index 0000000..4b97d8f --- /dev/null +++ b/test/specs/client.js @@ -0,0 +1,171 @@ +/** + * client + * Date: 26.05.15 + * Vitaliy V. Makeev (w.makeev@gmail.com) + */ + +var clientStamp = require('../../src/moysklad-client/client'); + +describe('client', function () { + + beforeEach(function () { + this.client = clientStamp(); + }); + + it('should have properties', function () { + + _.forEach([ + // client + 'from', + 'load', + 'chain', + 'first', + 'total', + 'save', + + // json service + 'stock', + 'stockForGood', + 'slot', + 'mutualSettlement', + 'mutualSettlementForCustomer', + + // operators + 'anyOf', + '$in', + 'between', + '$bt', + 'greaterThen', + '$gt', + 'greaterThanOrEqualTo', + '$gte', + 'lessThan', + '$lt', + 'lessThanOrEqualTo', + '$lte', + + // other + 'createQuery', + 'createLazyLoader', + 'loadMetadata', + 'options', + 'sortMode' + + ], function (prop) { + assert.ok(this.client[prop], 'client must have property [' + prop + ']'); + }, this); + + }); + + it('should have auth provider behavior', function () { + + expect(this.client).to.contain.all.keys( + 'setAuth', + 'getAuth', + 'getBasicAuthHeader', + 'isAuth' + ); + + }); + + it('should have provider accessor behavior', function () { + + expect(this.client).to.contain.all.keys( + 'getProvider', + 'setProvider' + ); + + }); + + it('should have classes constructor properties', function () { + + expect(this.client).to.contain.all.keys( + 'context', + 'AccountEntity', + 'CustomerOrder' + ); + + }); + + describe('entities', function () { + + describe('constructors properties', function () { + + it('should to be defined', function () { + var client = this.client; + + var CustomerOrder = + client.context.typeInfos['moysklad.customerOrder'].instanceFactory; + + expect(client.CustomerOrder) + .to.be.ok + .and.equal(CustomerOrder); + + assert.ok(client.AccountEntity, 'AccountEntity to be ok'); + }); + + it('should create entities instances', function () { + var client = this.client; + + var customerOrder = client.CustomerOrder({ + name: 'foo-order' + }); + + assert.ok(customerOrder, 'Instance of CustomerOrder to be ok'); + + expect(customerOrder.TYPE_NAME) + .equal('moysklad.customerOrder'); + + expect(customerOrder.name) + .equal('foo-order'); + + expect(customerOrder.getType) + .to.be.a('function'); + + expect(customerOrder.getType()).to.equal(customerOrder.TYPE_NAME); + }); + + }); + + describe('instances', function () { + + it('should have extended properties', function () { + var client = this.client; + + var accountEntity = client.AccountEntity(); + var customerOrder = client.CustomerOrder(); + + // AccountEntity properties + expect(accountEntity).to.have.property('getType'); + expect(customerOrder).to.have.property('getType'); + + // Aggregate only properties + expect(accountEntity).to.have.not.property('save'); + expect(customerOrder).to.have.property('save'); + + }); + + }); + + }); + + describe('methods', function () { + + beforeEach(function () { + //this.client + // .setProvider('ms-xml', msXmlClient) + // .setProvider('json-services', jsonServices); + }); + + describe('load', function () { + + it('should load entity by uuid', function () { + //var order = this.client.load('customerOrder', 'uuid'); + + }) + + }) + + }) + +}); \ No newline at end of file diff --git a/test/specs/model.js b/test/specs/model.js new file mode 100644 index 0000000..0dbed71 --- /dev/null +++ b/test/specs/model.js @@ -0,0 +1,121 @@ +/** + * model + * Date: 28.05.15 + * Vitaliy V. Makeev (w.makeev@gmail.com) + */ + +describe('model', function () { + + beforeEach(function () { + this.client = moysklad.createClient(); + }); + + + describe('customs', function () { + + beforeEach(function () { + this.customerOrder = this.client.CustomerOrder(); + }); + + it('should have methods', function () { + expect(this.customerOrder).to.have.property('save'); + expect(this.customerOrder).to.have.property('getAttr'); + expect(this.customerOrder).to.have.property('hasAttr'); + }); + + }); + + describe('accountEntity', function () { + + beforeEach(function () { + this.accountEntity = this.client.AccountEntity(); + }); + + it('should have methods', function () { + + var accountEntity = this.accountEntity; + + expect(accountEntity).to.have.property('getType'); + expect(accountEntity).to.have.property('instanceOf'); + expect(accountEntity).to.have.property('clone'); + expect(accountEntity).to.have.property('getProperty'); + + }); + + describe('instanceOf', function () { + + it('should test instance of entity', function () { + var customerOrder = this.client.CustomerOrder(); + var test = customerOrder.instanceOf('order'); + assert.ok( + customerOrder.instanceOf('order'), + 'customerOrder must be instance of order'); + + assert.ok( + customerOrder.instanceOf('moysklad.entity'), + 'customerOrder must be instance of entity'); + }); + + }); + + describe('getProperty', function () { + + it('should return property value for path', function () { + var customerOrder = this.client.CustomerOrder({ + foo: { + bar: 'order' + } + }); + expect(customerOrder.getProperty('foo.bar')).to.be.equal('order'); + }) + + }); + + }); + + describe('order', function () { + + it('should have "reserve" method', function () { + var customerOrder = this.client.CustomerOrder(); + expect(customerOrder).to.have.property('reserve'); + }); + + //TODO test + }); + + describe('operationWithPositions', function () { + + it('should have "getPositions" method', function () { + var customerOrder = this.client.CustomerOrder(); + expect(customerOrder).to.have.property('getPositions'); + }); + + //TODO test + }); + + describe('abstractGood', function () { + + it('should have "getPrice" method', function () { + var good = this.client.Good(); + expect(good).to.have.property('getPrice'); + }); + + it('should have "hasPrice" method', function () { + var good = this.client.Good(); + expect(good).to.have.property('hasPrice'); + }); + + //TODO test + }); + + describe('attributeValue', function () { + + it('should have "getValue" method', function () { + var attr = this.client.AttributeValue(); + expect(attr).to.have.property('getValue'); + }); + + //TODO test + }) + +}); \ No newline at end of file diff --git a/test/specs/moysklad.js b/test/specs/moysklad.js new file mode 100644 index 0000000..57eb50c --- /dev/null +++ b/test/specs/moysklad.js @@ -0,0 +1,20 @@ +/** + * moysklad-client + * Date: 16.07.14 + * Vitaliy V. Makeev (w.makeev@gmail.com) + */ + +describe('moysklad', function () { + + it('should have properties', function () { + expect(moysklad).to.have.all.keys( + 'createClient', + 'createQuery', + 'tools', + 'logger', + 'version' + ); + }); + +}); + diff --git a/test/specs/tools.js b/test/specs/tools.js new file mode 100644 index 0000000..004021c --- /dev/null +++ b/test/specs/tools.js @@ -0,0 +1,163 @@ +/** + * tools + * Date: 28.05.15 + * Vitaliy V. Makeev (w.makeev@gmail.com) + */ + +var tools = require('../../src/node_modules/project/tools'); + +// entity +var clone = tools.clone; +var hasAttr = tools.hasAttr; +var hasPrice = tools.hasPrice; +//var instanceOf = tools.instanceOf; + +// tools +var isUuid = tools.isUuid; +var getProperty = tools.getProperty; + + +describe('tools', function () { + + describe('entity', function () { + + describe('clone', function () { + + beforeEach(function () { + this.obj = { + name: 'order', + updated: new Date, + uuid: '123-456-789', + positions: [ + { name: 'pos-1', operationUuid: '234-567-890' }, + { name: 'pos-2' } + ], + field: { + subField: 'content', + uuid: '567-890-345' + } + }; + }); + + it('should clone object', function () { + + expect(clone(this.obj)).to.be.eql({ + name: 'order', + positions: [ + { name: 'pos-1' }, + { name: 'pos-2' } + ], + field: { + subField: 'content' + } + }); + + }); + + it('should not mutate source object', function () { + var cloned = clone(this.obj); + + expect(this.obj).to.contain.keys('uuid'); + expect(this.obj.field).to.contain.keys('uuid'); + }); + + }); + + describe('hasAttr', function () { + + it('should test entity for attribute exist', function () { + var entity = { + name: 'name', + attribute: [ + { + metadataUuid: '5f6e3b38-043f-11e5-7a07-673d0033e823' + }, + { + metadataUuid: '5f6e3b38-043f-11e5-7a07-673d0033e824' + } + ] + }; + + assert.ok(hasAttr(entity, '5f6e3b38-043f-11e5-7a07-673d0033e824')); + assert.notOk(hasAttr(entity, '5f6e3b38-043f-11e5-7a07-673d0033e825')); + + //TODO test exeptions + }); + + }); + + describe('hasPrice', function () { + + it('should test entity for price exist', function () { + var entity = { + name: 'name', + salePrices: [ + { + priceTypeUuid: '5f6e3b38-043f-11e5-7a07-673d0033e823' + }, + { + priceTypeUuid: '5f6e3b38-043f-11e5-7a07-673d0033e824' + } + ] + }; + + assert.ok(hasPrice(entity, '5f6e3b38-043f-11e5-7a07-673d0033e824')); + assert.notOk(hasPrice(entity, '5f6e3b38-043f-11e5-7a07-673d0033e825')); + + //TODO test exeptions + }); + + }); + + //describe('instanceOf', function () { + // + // it('should test entity is instance of', function () { + // assert.ok(instanceOf('customerOrder', 'order')); + // assert.ok(instanceOf('moysklad.customerOrder', 'order')); + // //TODO assert.ok(instanceOf(client.Order(), 'entity')); + // assert.notOk(instanceOf('order', 'moysklad.demand')); + // }); + // + //}); + + }); + + describe('isUuid', function () { + + it('should test for uuid', function () { + var uuid = '5f6e3b38-043f-11e5-7a07-673d0033e823'; + var not_uuid = 'this_is_not_uuid'; + + assert.ok(isUuid(uuid)); + assert.notOk(isUuid(not_uuid)); + }); + + }); + + describe('getProperty', function () { + + it('should return property value for path', function () { + + var obj = { + a: 'a', + b: { + c: 'c' + } + }; + + expect(getProperty(obj, 'a')).to.be.equal(obj.a); + expect(getProperty(obj, 'b.c')).to.be.equal(obj.b.c); + + assert.isUndefined(getProperty(obj, 'b.x')); + assert.isUndefined(obj.b.x); + + expect(getProperty(obj, 'b.x', 'foo')).to.be.equal('foo'); + assert.isUndefined(obj.b.x); + + expect(getProperty(obj, 'b.x', 'foo', true)).to.be.equal('foo'); + expect(obj.b.x).to.be.equal('foo'); + + }); + + }) +}); diff --git a/tests/specs/client.js b/tests/specs/client.js deleted file mode 100644 index 58fffa7..0000000 --- a/tests/specs/client.js +++ /dev/null @@ -1,40 +0,0 @@ -/** - * client - * Date: 16.07.14 - * Vitaliy V. Makeev (w.makeev@gmail.com) - */ - -var should = require('should'); -var moysklad = require('../..'); - -var load = require('../../src/moysklad-client/client/methods/load'); - -describe('client', function () { - - var client = moysklad.createClient(); - - it('should have properties', function(){ - moysklad.should.have.properties([ - 'createClient', - 'tools' - ]); - }); - - describe('load', function () { - - var loadContext = { - getProvider: function (providerName) { - return { - get: function () { - console.log(arguments); - } - }; - } - }; - - before(function () { - this.load ; - }) - - }) -}); \ No newline at end of file diff --git a/tests/specs/lazy-loader.js b/tests/specs/lazy-loader.js deleted file mode 100644 index 2a4ff54..0000000 --- a/tests/specs/lazy-loader.js +++ /dev/null @@ -1,7 +0,0 @@ -/** - * lazy-loader - * Date: 17.07.14 - * Vitaliy V. Makeev (w.makeev@gmail.com) - */ - -var createLazyLoader = require('../../src/moysklad-client/client/lazy-loader'); \ No newline at end of file diff --git a/tests/specs/moysklad-client.js b/tests/specs/moysklad-client.js deleted file mode 100644 index 577d5d9..0000000 --- a/tests/specs/moysklad-client.js +++ /dev/null @@ -1,17 +0,0 @@ -/** - * moysklad-client - * Date: 16.07.14 - * Vitaliy V. Makeev (w.makeev@gmail.com) - */ - -var should = require('should'); -var moysklad = require('..'); - -describe('moysklad-client', function(){ - it('should have properties', function(){ - moysklad.should.have.properties([ - 'createClient', - 'tools' - ]); - }) -}); \ No newline at end of file diff --git a/tests/specs/simple-test.js b/tests/specs/simple-test.js deleted file mode 100644 index e1d8cef..0000000 --- a/tests/specs/simple-test.js +++ /dev/null @@ -1,16 +0,0 @@ -/** - * simple-test - * Date: 27.03.14 - * Vitaliy V. Makeev (w.makeev@gmail.com) - */ - -var should = require('should'); - -describe('Array', function(){ - describe('#indexOf()', function(){ - it('should return -1 when the value is not present', function(){ - [1,2,3].indexOf(5).should.equal(-1); - [1,2,3].indexOf(0).should.equal(-1); - }) - }) -}); \ No newline at end of file