diff --git a/packages/teambition-sdk-core/src/index.ts b/packages/teambition-sdk-core/src/index.ts
index 96832b7f4..81cb5aeb1 100644
--- a/packages/teambition-sdk-core/src/index.ts
+++ b/packages/teambition-sdk-core/src/index.ts
@@ -1,9 +1,9 @@
///
import 'tslib'
-import { forEach, clone, uuid, concat, dropEle, pagination } from './utils/index'
+import { forEach, clone, uuid, concat, dropEle, pagination, capitalizeFirstLetter } from './utils/index'
-export const Utils = { forEach, clone, uuid, concat, dropEle, pagination }
+export const Utils = { forEach, clone, uuid, concat, dropEle, pagination, capitalizeFirstLetter }
export { PagingQuery, UrlPagingQuery } from './utils/internalTypes'
export { eventParser } from './sockets/EventParser'
diff --git a/packages/teambition-sdk-core/test/apis/index.ts b/packages/teambition-sdk-core/test/apis/index.ts
deleted file mode 100644
index dc47213cf..000000000
--- a/packages/teambition-sdk-core/test/apis/index.ts
+++ /dev/null
@@ -1,11 +0,0 @@
-import './event.spec'
-import './EventGenerator.spec'
-import './like.spec'
-import './my.spec'
-import './post.spec'
-import './task.spec'
-import './user.spec'
-import './file.spec'
-import './project.spec'
-import './search.spec'
-import './organization.spec'
diff --git a/packages/teambition-sdk-core/test/apis/organization.spec.ts b/packages/teambition-sdk-core/test/apis/organization.spec.ts
deleted file mode 100644
index 8e3a5b357..000000000
--- a/packages/teambition-sdk-core/test/apis/organization.spec.ts
+++ /dev/null
@@ -1,88 +0,0 @@
-import { describe, before, beforeEach, it, afterEach, after } from 'tman'
-import { expect } from 'chai'
-import { Scheduler } from 'rxjs'
-import { SDKFetch } from '../'
-import {
- getAllOrganizationProjects,
- getJoinedOrganizationProjects,
- getPublicOrganizationProjects,
- getStarredOrganizationProjects,
- getUngroupedOrganizationProjects
-} from '../../src/apis/organization/projects'
-
-const fetchMock = require('fetch-mock')
-
-describe('get organization projects', () => {
- describe('fetch apis', () => {
-
- let sdkFetch: SDKFetch
- let projects: any[]
- const sampleOrgId = '56f0d51e3cd13a5b537c3a12'
- const getOrganizationProjectsFns = () => [
- { fn: getAllOrganizationProjects, namespace: 'all' },
- { fn: getJoinedOrganizationProjects, namespace: 'joined' },
- { fn: getPublicOrganizationProjects, namespace: 'public' },
- { fn: getStarredOrganizationProjects, namespace: 'starred' },
- { fn: getUngroupedOrganizationProjects, namespace: 'ungrouped' }
- ]
-
- before(() => {
- SDKFetch.fetchTail = '666'
- })
-
- after(() => {
- SDKFetch.fetchTail = undefined
- })
-
- beforeEach(() => {
- sdkFetch = new SDKFetch()
- sdkFetch.setAPIHost('')
- projects = [
- { _id: 'A', tagId: '1', namespaces: ['all'] },
- { _id: 'B', tagId: '2', namespaces: ['all', 'joined'] },
- { _id: 'C', tagId: '2', namespaces: ['all', 'public'] },
- { _id: 'D', tagId: '2', namespaces: ['all', 'starred'] },
- { _id: 'E', tagId: '2', namespaces: ['all', 'ungrouped'] },
- { _id: 'F', tagId: '3', namespaces: ['all', 'joined', 'starred'] },
- { _id: 'G', tagId: '3', namespaces: ['all', 'joined', 'ungrouped'] },
- { _id: 'H', tagId: '4', namespaces: ['all', 'joined', 'public', 'starred'] },
- { _id: 'I', tagId: '3', namespaces: ['all', 'public', 'starred'] },
- { _id: 'J', tagId: '3', namespaces: ['all', 'starred', 'ungrouped'] },
- ]
- })
-
- afterEach(() => {
- fetchMock.restore()
- })
-
- getOrganizationProjectsFns().forEach(({ fn, namespace }) => {
- it(`${fn.name} should make correctly formatted request to target url and return response as it is`, function* () {
- const expectedUrl = `/organizations/${sampleOrgId}/projects/${namespace}?_=666`
- const expectedResponse = projects.filter(({ namespaces }) => new Set(namespaces).has(namespace))
-
- fetchMock.getOnce(expectedUrl, expectedResponse)
-
- yield fn.call(sdkFetch, sampleOrgId)
- .subscribeOn(Scheduler.async)
- .do((x: any) => {
- expect(x).to.deep.equal(expectedResponse)
- })
- })
- })
-
- it('getOrganizationProjectByTagId should make correctly formatted request to target url and return response as it is', function* () {
- const sampleTagId = '3'
- const expectedUrl = `/organizations/${sampleOrgId}/projecttags/${sampleTagId}/projects?_=666`
- const expectedResponse = projects.filter(({ tagId }) => tagId === sampleTagId)
-
- fetchMock.getOnce(expectedUrl, expectedResponse)
-
- yield sdkFetch.getOrganizationProjectsByTagId(sampleOrgId, sampleTagId)
- .subscribeOn(Scheduler.async)
- .do((x: any) => {
- expect(x).to.deep.equal(expectedResponse)
- })
- })
-
- })
-})
diff --git a/packages/teambition-sdk-core/test/apis/project.spec.ts b/packages/teambition-sdk-core/test/apis/project.spec.ts
deleted file mode 100644
index 048454d9b..000000000
--- a/packages/teambition-sdk-core/test/apis/project.spec.ts
+++ /dev/null
@@ -1,85 +0,0 @@
-import { describe, before, beforeEach, it, afterEach, after } from 'tman'
-import { expect } from 'chai'
-import { Scheduler } from 'rxjs'
-import {
- GetPersonalProjectsQueryParams
-} from '../../src/apis/project/personal'
-import { SDKFetch } from '../'
-
-const fetchMock = require('fetch-mock')
-
-describe('get personal projects', () => {
- describe('fetch api', () => {
-
- let sdkFetch: SDKFetch
- let projects: any[]
-
- before(() => {
- SDKFetch.fetchTail = '666'
- })
-
- after(() => {
- SDKFetch.fetchTail = undefined
- })
-
- beforeEach(() => {
- sdkFetch = new SDKFetch()
- sdkFetch.setAPIHost('')
- projects = [
- { _id: 'A' },
- { _id: 'B', isArchived: true },
- { _id: 'C', isArchived: true, isStar: true },
- { _id: 'D', isStar: true }
- ]
- })
-
- afterEach(() => {
- fetchMock.restore()
- })
-
- const sampleParams: Partial[] = [
- {},
- { isArchived: true },
- { isArchived: false },
- { isStar: true },
- { isStar: false },
- { isArchived: true, isStar: true },
- { isArchived: true, isStar: false },
- { isArchived: false, isStar: false },
- { isArchived: false, isStar: true }
- ]
-
- sampleParams.forEach(({ isArchived, isStar }) => {
-
- const isArchivedMsg = isArchived === undefined ? '' : `isArchived=${isArchived}`
- const isStarMsg = isStar === undefined ? '' : `isStar=${isStar}`
-
- it(`should be able to get ${isArchivedMsg} ${isStarMsg} personal projects`, function* () {
- let expectedUrl = '/projects/personal?'
- if (!isArchivedMsg && !isStarMsg) {
- expectedUrl += '_=666'
- } else if (isArchivedMsg && isStarMsg) {
- expectedUrl += `${isArchivedMsg}&${isStarMsg}&_=666`
- } else if (isArchivedMsg) {
- expectedUrl += `${isArchivedMsg}&_=666`
- } else if (isStarMsg) {
- expectedUrl += `${isStarMsg}&_=666`
- }
- const expectedResponse = projects.filter((x: any) => x.isArchived == isArchived && x.isStar == isStar)
-
- fetchMock.getOnce(expectedUrl, expectedResponse)
-
- const params = {
- ...(isArchived === undefined ? {} : { isArchived }),
- ...(isStar === undefined ? {} : { isStar })
- }
-
- yield sdkFetch.getPersonalProjects(params as any)
- .subscribeOn(Scheduler.async)
- .do((x: any) => {
- expect(x).to.deep.equal(expectedResponse)
- })
- })
- })
- })
-})
diff --git a/packages/teambition-sdk-core/test/apis/search.spec.ts b/packages/teambition-sdk-core/test/apis/search.spec.ts
deleted file mode 100644
index 08994f4fb..000000000
--- a/packages/teambition-sdk-core/test/apis/search.spec.ts
+++ /dev/null
@@ -1,169 +0,0 @@
-import { describe, before, beforeEach, it, afterEach, after } from 'tman'
-import { expect } from 'chai'
-import { Scheduler } from 'rxjs'
-import {
- searchMembersInTeam,
- searchMembersInProject,
- searchMembersInOrganization,
- searchMembersInGroup,
- ScopeType,
- buildPath as buildPathForMemberSearching
-} from '../../src/apis/search/members'
-import { SDKFetch } from '../'
-
-const fetchMock = require('fetch-mock')
-
-describe('search for members', () => {
- describe('buildPath', () => {
- it('should build global member search on {}', () => {
- expect(buildPathForMemberSearching({})).to.equal('members/search')
- })
-
- it('should return null on invalid scope', () => {
- [
- { id: '58de087921efc137f43cef3c' },
- { type: ScopeType.Organization },
- { id: '58de087921efc137f43cef3c', type: -1 },
- ].forEach((scope: any) => {
- expect(buildPathForMemberSearching(scope)).to.be.null
- })
- })
-
- it('should build correct path for each type of scopes', () => {
- const sampleId = '58de087921efc137f43cef3c'
- expect(buildPathForMemberSearching({
- type: ScopeType.Team,
- id: sampleId
- })).to.equal(`teams/${sampleId}/members/search`)
-
- expect(buildPathForMemberSearching({
- type: ScopeType.Project,
- id: sampleId
- })).to.equal(`projects/${sampleId}/members/search`)
-
- expect(buildPathForMemberSearching({
- type: ScopeType.Organization,
- id: sampleId
- })).to.equal(`organizations/${sampleId}/members/search`)
-
- expect(buildPathForMemberSearching({
- type: ScopeType.Group,
- id: sampleId
- })).to.equal(`groups/${sampleId}/members/search`)
- })
- })
-
- describe('apis', () => {
-
- let sdkFetch: SDKFetch
- let allMembers: any
- const sampleId = '58de087921efc137f43cef3c'
- const searchMembersInScopeFns = () => [
- { fn: searchMembersInTeam, namespace: 'teams' },
- { fn: searchMembersInProject, namespace: 'projects' },
- { fn: searchMembersInOrganization, namespace: 'organizations' },
- { fn: searchMembersInGroup, namespace: 'groups' },
- ]
-
- before(() => {
- SDKFetch.fetchTail = '666'
- })
-
- after(() => {
- SDKFetch.fetchTail = undefined
- })
-
- beforeEach(() => {
- sdkFetch = new SDKFetch()
- sdkFetch.setAPIHost('') // 下面的测试不关心 API host 设置
- allMembers = [
- {
- _id: '55c02018fd0360a44c93ff97',
- name: '宝宝摔倒了',
- avatarUrl: 'http://striker.project.ci/thumbnail/010u39ad2e6022ef3ac616c42a46625095ab/w/200/h/200',
- email: '123@123.com'
- },
- {
- _id: '585cbb213e6b5a63f259a23d',
- name: '宝宝',
- avatarUrl: 'http://striker.project.ci/thumbnail/010r5c002c5205b60acfc42386bfa98cac1f/w/200/h/200',
- email: 'test1229@test.com'
- }
- ]
- })
-
- afterEach(() => {
- fetchMock.restore()
- })
-
- searchMembersInScopeFns().forEach(({ fn, namespace }) => {
- it(`${fn.name} should handle empty search string correctly`, function* () {
- const expectedResultSet: any[] = allMembers
- fetchMock.getOnce(`/${namespace}/${sampleId}/members/search?q=&_=666`, expectedResultSet)
-
- yield fn.call(sdkFetch, sampleId as any, '')
- .subscribeOn(Scheduler.async)
- .do((x: any) => {
- expect(x).to.deep.equal(expectedResultSet)
- })
- })
- })
-
- searchMembersInScopeFns().forEach(({ fn, namespace }) => {
- it(`${fn.name} should return empty result set as it is`, function* () {
- const expectedResultSet: any[] = []
- fetchMock.getOnce(`/${namespace}/${sampleId}/members/search?q=nonExistence&_=666`, expectedResultSet)
-
- yield fn.call(sdkFetch, sampleId as any, 'nonExistence')
- .subscribeOn(Scheduler.async)
- .do((x: any) => {
- expect(x).to.deep.equal(expectedResultSet)
- })
- })
- })
-
- searchMembersInScopeFns().forEach(({ fn, namespace }) => {
- it(`${fn.name} should handle normal cases correctly`, function* () {
- const expectedResultSet: any[] = allMembers.slice(0, 1)
- fetchMock.getOnce(`/${namespace}/${sampleId}/members/search?q=shuai&_=666`, expectedResultSet)
-
- yield fn.call(sdkFetch, sampleId as any, 'shuai')
- .subscribeOn(Scheduler.async)
- .do((x: any) => {
- expect(x).to.deep.equal(expectedResultSet)
- })
- })
- })
-
- it('searchMembers should handle empty search string correctly', function* () {
- fetchMock.get('/members/search?q=&_=666', allMembers)
-
- yield sdkFetch.searchMembers('')
- .subscribeOn(Scheduler.async)
- .do((x) => {
- expect(x).to.deep.equal(allMembers)
- })
- })
-
- it('searchMembers should return empty result set as it is', function* () {
- fetchMock.get('/members/search?q=nonExistence&_=666', [])
-
- yield sdkFetch.searchMembers('nonExistence')
- .subscribeOn(Scheduler.async)
- .do((x) => {
- expect(x).to.deep.equal([])
- })
- })
-
- it('searchMembers should handle normal cases correctly', function* () {
- const expectedResultSet = allMembers.slice(0, 1)
- fetchMock.get('/members/search?q=shuai&_=666', expectedResultSet)
-
- yield sdkFetch.searchMembers('shuai')
- .subscribeOn(Scheduler.async)
- .do((x) => {
- expect(x).to.deep.equal(expectedResultSet)
- })
- })
- })
-})
diff --git a/packages/teambition-sdk-core/test/app.ts b/packages/teambition-sdk-core/test/app.ts
index b4db5b3b9..0d4b63421 100644
--- a/packages/teambition-sdk-core/test/app.ts
+++ b/packages/teambition-sdk-core/test/app.ts
@@ -9,6 +9,5 @@ export * from './utils/httpErrorSpec'
export * from './mock/MockSpec'
-import './apis'
import './sockets'
import './net'
diff --git a/packages/teambition-sdk-request/package.json b/packages/teambition-sdk-request/package.json
index a9edae81d..c869b2952 100644
--- a/packages/teambition-sdk-request/package.json
+++ b/packages/teambition-sdk-request/package.json
@@ -7,7 +7,7 @@
"scripts": {
"build_cjs": "rm -rf dist/cjs && tsc src/index.ts -m commonjs --outDir dist/cjs --sourcemap --inlineSources --target ES5 -d --diagnostics --pretty --strict --noUnusedLocals --noUnusedParameters --experimentalDecorators --suppressImplicitAnyIndexErrors --moduleResolution node --importHelpers --noEmitHelpers --lib es5,es2015.iterable,es2015.collection,es2015.promise,es2015.core,dom",
"build_test": "rm -rf spec-js && tsc test/app.ts -m commonjs --sourcemap --inlineSources --outDir spec-js --target ES2015 --diagnostics --pretty --experimentalDecorators --suppressImplicitAnyIndexErrors --types \"node,chai,sinon,sinon-chai\" --moduleResolution node",
- "cover": "npm run build_test && rm -rf ./coverage && nyc --reporter=html --reporter=lcov --exclude=node_modules --exclude=spec-js/test --exclude=spec-js/mock --exclude=spec-js/src/sockets/SocketClient.js tman --mocha spec-js/test/app.js",
+ "cover": "npm run build_test && tman --mocha spec-js/test/app.js",
"lint": "tslint ./src/**/*.ts ./mock/**/*.ts ./test/*.ts ./test/apis/**/*.ts ./test/mock/**/*.ts ./test/utils/**/*.ts",
"test": "npm run lint && npm run cover"
},
diff --git a/packages/teambition-sdk-request/src/user/index.ts b/packages/teambition-sdk-request/src/user/index.ts
index 82563d92b..d4a99703d 100644
--- a/packages/teambition-sdk-request/src/user/index.ts
+++ b/packages/teambition-sdk-request/src/user/index.ts
@@ -1,2 +1,3 @@
+import './addEmail'
import './get'
import './update'
diff --git a/packages/teambition-sdk-core/test/apis/EventGenerator.spec.ts b/packages/teambition-sdk-request/test/apis/EventGenerator.spec.ts
similarity index 97%
rename from packages/teambition-sdk-core/test/apis/EventGenerator.spec.ts
rename to packages/teambition-sdk-request/test/apis/EventGenerator.spec.ts
index c4c66b2a3..6e9f24be0 100644
--- a/packages/teambition-sdk-core/test/apis/EventGenerator.spec.ts
+++ b/packages/teambition-sdk-request/test/apis/EventGenerator.spec.ts
@@ -8,8 +8,8 @@ import {
emptyRecurrence,
normalEvent
} from '../fixtures/events.fixture'
-import { EventGenerator } from '../../src/apis/event/EventGenerator'
-import { clone } from '../index'
+import { EventGenerator } from '../../src/event/EventGenerator'
+import { Utils } from 'teambition-sdk-core'
describe('EventGenerator spec', () => {
let eventGenerator: EventGenerator
@@ -31,7 +31,7 @@ describe('EventGenerator spec', () => {
it('should get next event for a recurrent event', () => {
const nextEvent = eventGenerator.next()
- const expected = clone(recurrenceByMonth);
+ const expected = Utils.clone(recurrenceByMonth);
['_id', 'startDate', 'endDate']
.forEach(f => {
delete nextEvent.value![f]
@@ -76,7 +76,7 @@ describe('EventGenerator spec', () => {
const egen = new EventGenerator(recurrenceStartAtAnExcludedDate as any)
const actual = egen.next().value!
delete actual['_id']
- const expected = clone(recurrenceStartAtAnExcludedDate)
+ const expected = Utils.clone(recurrenceStartAtAnExcludedDate)
delete expected['_id']
expected.startDate = '2017-06-07T09:00:00.000Z'
expected.endDate = '2017-06-07T10:00:00.000Z'
@@ -245,7 +245,7 @@ describe('EventGenerator spec', () => {
let startDate = new Date(recurrenceByMonth.startDate)
const firstMonthEvent = eventGenerator.after(startDate)
delete firstMonthEvent!['_id']
- const firstEvent = clone(recurrenceByMonth)
+ const firstEvent = Utils.clone(recurrenceByMonth)
delete firstEvent['_id']
expect(firstMonthEvent).to.deep.equal(firstEvent)
diff --git a/packages/teambition-sdk-core/test/apis/event.spec.ts b/packages/teambition-sdk-request/test/apis/event.spec.ts
similarity index 96%
rename from packages/teambition-sdk-core/test/apis/event.spec.ts
rename to packages/teambition-sdk-request/test/apis/event.spec.ts
index ea0ec4db1..a91d8d2a3 100644
--- a/packages/teambition-sdk-core/test/apis/event.spec.ts
+++ b/packages/teambition-sdk-request/test/apis/event.spec.ts
@@ -1,11 +1,12 @@
import * as moment from 'moment'
import { describe, beforeEach, afterEach, it } from 'tman'
import { expect } from 'chai'
-import { createSdk, SDK, SocketMock, EventSchema } from '../index'
+import { SDK, EventSchema } from 'teambition-sdk-core'
+import { createSdk, SocketMock } from '../index'
import * as Fixture from '../fixtures/events.fixture'
import { mock, restore, equals, looseDeepEqual, clone } from '../utils'
-describe('EventApi Spec', () => {
+describe.only('EventApi Spec', () => {
let sdk: SDK
let mockResponse: (m: T, delay?: number | Promise) => void
let socket: SocketMock
diff --git a/packages/teambition-sdk-core/test/apis/file.spec.ts b/packages/teambition-sdk-request/test/apis/file.spec.ts
similarity index 95%
rename from packages/teambition-sdk-core/test/apis/file.spec.ts
rename to packages/teambition-sdk-request/test/apis/file.spec.ts
index bca361264..c641f2bec 100644
--- a/packages/teambition-sdk-core/test/apis/file.spec.ts
+++ b/packages/teambition-sdk-request/test/apis/file.spec.ts
@@ -1,6 +1,7 @@
import { describe, beforeEach, afterEach, it } from 'tman'
import { expect } from 'chai'
-import { createSdk, SDK, SocketMock, FileSchema } from '../index'
+import { SDK, FileSchema } from 'teambition-sdk-core'
+import { createSdk, SocketMock } from '../index'
import * as Fixture from '../fixtures/files.fixture'
import { mock, restore, looseDeepEqual } from '../utils'
diff --git a/packages/teambition-sdk-request/test/apis/index.ts b/packages/teambition-sdk-request/test/apis/index.ts
index cba56d824..8b28cb4c3 100644
--- a/packages/teambition-sdk-request/test/apis/index.ts
+++ b/packages/teambition-sdk-request/test/apis/index.ts
@@ -1,11 +1,11 @@
// import './event.spec'
-// import './EventGenerator.spec'
+import './EventGenerator.spec'
+// import './file.spec'
// import './like.spec'
// import './my.spec'
+import './organization.spec'
// import './post.spec'
-// import './task.spec'
-// import './user.spec'
-// import './file.spec'
import './project.spec'
import './search.spec'
-import './organization.spec'
+// import './task.spec'
+// import './user.spec'
diff --git a/packages/teambition-sdk-core/test/apis/like.spec.ts b/packages/teambition-sdk-request/test/apis/like.spec.ts
similarity index 93%
rename from packages/teambition-sdk-core/test/apis/like.spec.ts
rename to packages/teambition-sdk-request/test/apis/like.spec.ts
index 2df39b09e..c2ea2351f 100644
--- a/packages/teambition-sdk-core/test/apis/like.spec.ts
+++ b/packages/teambition-sdk-request/test/apis/like.spec.ts
@@ -1,7 +1,8 @@
'use strict'
import { expect } from 'chai'
import { describe, it, beforeEach, afterEach } from 'tman'
-import { createSdk, SocketMock, SDK, LikeSchema } from '../index'
+import { SDK, LikeSchema } from 'teambition-sdk-core'
+import { createSdk, SocketMock } from '../index'
import like from '../fixtures/like.fixture'
import { mock, restore } from '../utils'
diff --git a/packages/teambition-sdk-core/test/apis/my.spec.ts b/packages/teambition-sdk-request/test/apis/my.spec.ts
similarity index 92%
rename from packages/teambition-sdk-core/test/apis/my.spec.ts
rename to packages/teambition-sdk-request/test/apis/my.spec.ts
index ae1362aff..eaeddf911 100644
--- a/packages/teambition-sdk-core/test/apis/my.spec.ts
+++ b/packages/teambition-sdk-request/test/apis/my.spec.ts
@@ -1,7 +1,8 @@
import { describe, it, beforeEach, afterEach } from 'tman'
import { expect } from 'chai'
-import { createSdk, SocketMock, SDK, TaskSchema } from '../index'
-import { EventGenerator } from '../../src/apis/event/EventGenerator'
+import { SDK, TaskSchema } from 'teambition-sdk-core'
+import { createSdk, SocketMock } from '../index'
+import { EventGenerator } from '../../src/event/EventGenerator'
import * as Fixture from '../fixtures/my.fixture'
import { mock, restore } from '../utils'
diff --git a/packages/teambition-sdk-core/test/apis/post.spec.ts b/packages/teambition-sdk-request/test/apis/post.spec.ts
similarity index 98%
rename from packages/teambition-sdk-core/test/apis/post.spec.ts
rename to packages/teambition-sdk-request/test/apis/post.spec.ts
index 3df03ae61..b647ef4a2 100644
--- a/packages/teambition-sdk-core/test/apis/post.spec.ts
+++ b/packages/teambition-sdk-request/test/apis/post.spec.ts
@@ -1,6 +1,7 @@
import { describe, beforeEach, afterEach, it } from 'tman'
import { expect } from 'chai'
-import { createSdk, SDK, PostSchema, SocketMock } from '../index'
+import { SDK, PostSchema } from 'teambition-sdk-core'
+import { createSdk, SocketMock } from '../index'
import { projectPosts, myProjectPosts, tagPosts } from '../fixtures/posts.fixture'
import { mock, restore, equals } from '../utils'
import { shuffle } from 'lodash'
diff --git a/packages/teambition-sdk-core/test/apis/task.spec.ts b/packages/teambition-sdk-request/test/apis/task.spec.ts
similarity index 95%
rename from packages/teambition-sdk-core/test/apis/task.spec.ts
rename to packages/teambition-sdk-request/test/apis/task.spec.ts
index 80adf5eac..ab45796cf 100644
--- a/packages/teambition-sdk-core/test/apis/task.spec.ts
+++ b/packages/teambition-sdk-request/test/apis/task.spec.ts
@@ -1,6 +1,7 @@
import { describe, beforeEach, afterEach, it } from 'tman'
import { expect } from 'chai'
-import { createSdk, SDK, SocketMock, TaskSchema } from '../index'
+import { SDK, TaskSchema } from 'teambition-sdk-core'
+import { createSdk, SocketMock } from '../index'
import * as Fixture from '../fixtures/tasks.fixture'
import { mock, restore, looseDeepEqual } from '../utils'
diff --git a/packages/teambition-sdk-core/test/apis/user.spec.ts b/packages/teambition-sdk-request/test/apis/user.spec.ts
similarity index 95%
rename from packages/teambition-sdk-core/test/apis/user.spec.ts
rename to packages/teambition-sdk-request/test/apis/user.spec.ts
index 3d08ee388..e8a867910 100644
--- a/packages/teambition-sdk-core/test/apis/user.spec.ts
+++ b/packages/teambition-sdk-request/test/apis/user.spec.ts
@@ -1,6 +1,7 @@
import { describe, beforeEach, afterEach, it } from 'tman'
import { expect } from 'chai'
-import { createSdk, SDK, SocketMock, UserMe } from '../index'
+import { SDK, UserMe } from 'teambition-sdk-core'
+import { createSdk, SocketMock } from '../index'
import userMe from '../fixtures/user.fixture'
import { mock, restore } from '../utils'
diff --git a/packages/teambition-sdk-core/test/fixtures/events.fixture.ts b/packages/teambition-sdk-request/test/fixtures/events.fixture.ts
similarity index 100%
rename from packages/teambition-sdk-core/test/fixtures/events.fixture.ts
rename to packages/teambition-sdk-request/test/fixtures/events.fixture.ts
diff --git a/packages/teambition-sdk-core/test/fixtures/files.fixture.ts b/packages/teambition-sdk-request/test/fixtures/files.fixture.ts
similarity index 100%
rename from packages/teambition-sdk-core/test/fixtures/files.fixture.ts
rename to packages/teambition-sdk-request/test/fixtures/files.fixture.ts
diff --git a/packages/teambition-sdk-core/test/fixtures/like.fixture.ts b/packages/teambition-sdk-request/test/fixtures/like.fixture.ts
similarity index 100%
rename from packages/teambition-sdk-core/test/fixtures/like.fixture.ts
rename to packages/teambition-sdk-request/test/fixtures/like.fixture.ts
diff --git a/packages/teambition-sdk-core/test/fixtures/my.fixture.ts b/packages/teambition-sdk-request/test/fixtures/my.fixture.ts
similarity index 99%
rename from packages/teambition-sdk-core/test/fixtures/my.fixture.ts
rename to packages/teambition-sdk-request/test/fixtures/my.fixture.ts
index 44724e4a0..6409b5f6e 100644
--- a/packages/teambition-sdk-core/test/fixtures/my.fixture.ts
+++ b/packages/teambition-sdk-request/test/fixtures/my.fixture.ts
@@ -1,5 +1,5 @@
-import { EventSchema } from '../index'
-import { EventGenerator } from '../../src/apis/event/EventGenerator'
+import { EventSchema } from 'teambition-sdk-core'
+import { EventGenerator } from '../../src/event/EventGenerator'
export function norm(myRecent: any[]): any[] {
const transFns: any[] = [firstOfARecurrentEvent]
diff --git a/packages/teambition-sdk-core/test/fixtures/posts.fixture.ts b/packages/teambition-sdk-request/test/fixtures/posts.fixture.ts
similarity index 100%
rename from packages/teambition-sdk-core/test/fixtures/posts.fixture.ts
rename to packages/teambition-sdk-request/test/fixtures/posts.fixture.ts
diff --git a/packages/teambition-sdk-core/test/fixtures/tasks.fixture.ts b/packages/teambition-sdk-request/test/fixtures/tasks.fixture.ts
similarity index 100%
rename from packages/teambition-sdk-core/test/fixtures/tasks.fixture.ts
rename to packages/teambition-sdk-request/test/fixtures/tasks.fixture.ts
diff --git a/packages/teambition-sdk-core/test/fixtures/user.fixture.ts b/packages/teambition-sdk-request/test/fixtures/user.fixture.ts
similarity index 100%
rename from packages/teambition-sdk-core/test/fixtures/user.fixture.ts
rename to packages/teambition-sdk-request/test/fixtures/user.fixture.ts
diff --git a/packages/teambition-sdk-request/test/index.ts b/packages/teambition-sdk-request/test/index.ts
index 3bdc94cd1..b9423ba60 100644
--- a/packages/teambition-sdk-request/test/index.ts
+++ b/packages/teambition-sdk-request/test/index.ts
@@ -1 +1,15 @@
+'use strict'
+import { Database, DataStoreType } from 'reactivedb'
+import { SDK } from 'teambition-sdk-core'
+
+export function createSdk() {
+ const sdk = new SDK()
+
+ const database = new Database(DataStoreType.MEMORY, false, 'teambition-sdk', 1)
+ sdk.initReactiveDB(database)
+
+ return sdk
+}
+
export * from '../src/index'
+export * from '../../../mock/index'
diff --git a/packages/teambition-sdk-request/test/mock/MockFetch.ts b/packages/teambition-sdk-request/test/mock/MockFetch.ts
new file mode 100644
index 000000000..9b6549aa7
--- /dev/null
+++ b/packages/teambition-sdk-request/test/mock/MockFetch.ts
@@ -0,0 +1,45 @@
+import { SDKFetch } from 'teambition-sdk-core'
+import { Backend } from '../../../../mock'
+
+function throwIfSlashPath(path: string) {
+ if (path.charAt(0) === '/') {
+ throw new Error(`There shouldn't be a slash before path (${path})`)
+ }
+}
+
+export class MockFetch extends SDKFetch {
+ private httpBackend = new Backend
+ private _apiHost = new SDKFetch().getAPIHost()
+
+ mockGet(path: string, query?: any) {
+ throwIfSlashPath(path)
+ return {
+ mockResponse: this.httpBackend.whenGET(`${this._apiHost}/${path}`, query),
+ request: this.get(path, query)
+ }
+ }
+
+ mockPut(path: string, body?: any) {
+ throwIfSlashPath(path)
+ return {
+ mockResponse: this.httpBackend.whenPUT(`${this._apiHost}/${path}`, body),
+ request: this.put(path, body)
+ }
+ }
+
+ mockPost(path: string, body?: any) {
+ throwIfSlashPath(path)
+ return {
+ mockResponse: this.httpBackend.whenPOST(`${this._apiHost}/${path}`, body),
+ request: this.post(path, body)
+ }
+ }
+
+ mockDelete(path: string) {
+ throwIfSlashPath(path)
+ return {
+ mockResponse: this.httpBackend.whenDELETE(`${this._apiHost}/${path}`),
+ request: this.delete(path)
+ }
+ }
+}
diff --git a/packages/teambition-sdk-request/test/utils.ts b/packages/teambition-sdk-request/test/utils.ts
new file mode 100644
index 000000000..993f47b17
--- /dev/null
+++ b/packages/teambition-sdk-request/test/utils.ts
@@ -0,0 +1,83 @@
+'use strict'
+import { expect } from 'chai'
+import { SDK, SDKFetch, Utils } from 'teambition-sdk-core'
+import { MockFetch } from './mock/MockFetch'
+
+export function notInclude(collection: any[], ele: any) {
+ let result = true
+ const unionFlag = ele['_id']
+ Utils.forEach(collection, val => {
+ if (val['_id'] === unionFlag) {
+ result = false
+ }
+ })
+ return result
+}
+
+export function clone (a: T): T {
+ return JSON.parse(JSON.stringify(a))
+}
+
+/**
+ * deep equal between a and b
+ * loose property compare
+ * a: {
+ * foo: 1,
+ * bar: 2
+ * }
+ * b: {
+ * foo: 1,
+ * bar: 2,
+ * baz: 3
+ * }
+ * equals(a, b) // pass
+ */
+export function equals(a: any, b: any) {
+ const _a = clone(a)
+ const _b = clone(b)
+ Utils.forEach(_b, (_, key) => {
+ if (typeof a[key] === 'undefined') {
+ delete _b[key]
+ }
+ })
+ function deleteUndefined(obj: any) {
+ Utils.forEach(obj, (val, key) => {
+ if (typeof val === 'undefined') {
+ delete _a[key]
+ } else if (val && typeof val === 'object') {
+ deleteUndefined(val)
+ }
+ })
+ }
+ deleteUndefined(_a)
+ expect(_a).to.deep.equal(_b)
+}
+
+export function looseDeepEqual(a: any, b: any) {
+ Utils.forEach(a, (val, key) => {
+ if (val && typeof val === 'object') {
+ looseDeepEqual(val, b[key])
+ } else if (val) {
+ expect(val).to.deep.equal(b[key])
+ }
+ })
+}
+
+export function mock(sdk: SDK) {
+ const mockFetch = new MockFetch
+ const methods = ['get', 'put', 'post', 'delete']
+
+ return (m: T, schedule?: number | Promise) => {
+ methods.forEach(method => {
+ sdk.fetch[method] = function(url: string, arg2?: any) {
+ const mockResult = mockFetch[`mock${Utils.capitalizeFirstLetter(method)}`](url, arg2)
+ mockResult.mockResponse.respond(m, schedule)
+ return mockResult.request
+ }
+ })
+ }
+}
+
+export function restore(sdk: SDK) {
+ sdk.fetch = new SDKFetch
+}
diff --git a/tools/tasks/test.ts b/tools/tasks/test.ts
index fe451fa80..dd7a77cb4 100644
--- a/tools/tasks/test.ts
+++ b/tools/tasks/test.ts
@@ -1,3 +1,5 @@
+import { exec } from 'child_process'
+import * as fs from 'fs'
import * as path from 'path'
import { Observable, Observer } from 'rxjs'
@@ -31,15 +33,54 @@ function watch (paths: string[]) {
.debounceTime(300)
}
-watch(['spec-js'])
- .subscribe(() => {
- runTman()
- }, err => {
- console.error(err)
- })
+namespace print {
+ const green = '\x1b[0m\x1b[32m'
+ const red = '\x1b[0m\x1b[31m'
+ const blank = '\x1b[0m\x1b[00m'
+
+ export function good(...strings) {
+ console.info('\n', green, ...strings, blank, '\n')
+ }
+
+ export function bad(...strings) {
+ console.info('\n', red, ...strings, blank, '\n')
+ }
+}
+
+const path2packages = '../../packages'
-process.on('uncaughtException', (err: any) => {
- console.info(`Caught exception: ${err.stack}`)
+const pkgdirs = fs.readdirSync(path2packages)
+console.info(pkgdirs)
+
+pkgdirs.forEach((pkgdir) => {
+ const path2pkg = path.join(path2packages, pkgdir)
+ console.info('path2pkg', path2pkg)
+
+ const pkgjson = JSON.parse(fs.readFileSync(path.join(path2pkg, 'package.json'), 'utf8'))
+ const buildtestCmd = pkgjson['scripts']['build_test']
+ console.info('cmd', buildtestCmd)
+
+ console.info('\nstart building test for:', pkgdir, '\n')
+ exec(buildtestCmd, { cwd: path2pkg }, (error, stdout, stderr) => {
+ if (error !== null) {
+ print.bad('failed to run build_test cmd for:', pkgdir)
+ console.error(stderr)
+ console.info(stdout)
+ console.error(error)
+ return
+ }
+ print.good('finished building test for:', pkgdir)
+ })
})
-console.info('\x1b[1m\x1b[34mwatch start\x1b[39m\x1b[22m')
+// watch(['spec-js'])
+// .subscribe(() => {
+// runTman()
+// }, err => {
+// console.error(err)
+// })
+// process.on('uncaughtException', (err: any) => {
+// console.info(`Caught exception: ${err.stack}`)
+// })
+
+// console.info('\x1b[1m\x1b[34mwatch start\x1b[39m\x1b[22m')
diff --git a/tools/tslint.json b/tools/tslint.json
new file mode 100644
index 000000000..38ebefa73
--- /dev/null
+++ b/tools/tslint.json
@@ -0,0 +1,6 @@
+{
+ "extends": ["../tslint.json"],
+ "rules": {
+ "no-shadowed-variable": false
+ }
+}