-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: ✨ teams implementation with unit and api tests
- Loading branch information
1 parent
aac5cf4
commit dba8f48
Showing
7 changed files
with
260 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
import cloneDeep from 'lodash/cloneDeep' | ||
import { | ||
create, | ||
fetch, | ||
update, | ||
query, | ||
deleteEntity, | ||
parseData, | ||
fetchAll | ||
} from '../../entity' | ||
|
||
export function Teams (http, data) { | ||
this.organization_uid = data.organization_uid | ||
|
||
this.urlPath = `/organizations/${this.organization_uid}/teams` | ||
|
||
if (data && data.team) { | ||
Object.assign(this, cloneDeep(data.team)) | ||
console.log('org uid 2', this.organization_uid) | ||
|
||
this.urlPath = `/organizations/${this.organization_uid}/teams/${this.uid}` | ||
|
||
this.update = update(http, 'team') | ||
|
||
this.delete = deleteEntity(http) | ||
|
||
this.fetch = fetch(http, 'team') | ||
} else { | ||
this.create = create({ http }) | ||
this.query = fetchAll(http, TeamsCollection) | ||
// this.query = query({ http: http, wrapperCollection: TeamsCollection }) | ||
} | ||
} | ||
export function TeamsCollection (http, teamsData) { | ||
const obj = cloneDeep(teamsData.teams) || [] | ||
const teamsCollection = obj.map((team) => { | ||
return new Teams(http, { team: team }) | ||
}) | ||
return teamsCollection | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,78 @@ | ||
import { describe, it, beforeEach } from 'mocha' | ||
import { expect } from 'chai' | ||
import { jsonReader } from '../utility/fileOperations/readwrite' | ||
// import * as contentstack from '../../lib/contentstack.js' | ||
import { contentstackClient } from '../utility/ContentstackClient.js' | ||
|
||
var client = {} | ||
|
||
var org_uid = 'blt242b133b4e9bd736' | ||
const team_uid = '6539eed4b502f0a73415188e' | ||
const team = { | ||
name: 'team_name', | ||
users: [], | ||
stackRoleMapping: [], | ||
organizationRole: 'organization_role_uid' | ||
} | ||
|
||
describe('Teams API Test', () => { | ||
beforeEach(() => { | ||
const user = jsonReader('loggedinuser.json') | ||
client = contentstackClient(user.authtoken) | ||
}) | ||
it('Query and get all teams', async () => { | ||
try { | ||
const response = await client.organization(org_uid).teams().query() | ||
console.log('res', response) | ||
} catch (err) { | ||
console.log(err) | ||
} | ||
}) | ||
it('fetch test', async () => { | ||
try { | ||
const response = await client.organization(org_uid).teams(team_uid).fetch() | ||
console.log('res2', await response) | ||
} catch (err) { | ||
console.log(err) | ||
} | ||
}) | ||
// it('create test', async () => { | ||
// try { | ||
// const response = await makeTeams(org_uid).create({ | ||
// name: 't2', | ||
// users: [], | ||
// stackRoleMapping: [], | ||
// organizationRole: 'blt09e5dfced326aaea' }) | ||
// console.log('res2', response) | ||
// } catch (err) { | ||
// console.log(err) | ||
// } | ||
// }) | ||
// it('delete test', async () => { | ||
// try { | ||
// const response = await makeTeams(org_uid, '').delete() | ||
// console.log('res2', response) | ||
// } catch (err) { | ||
// console.log(err) | ||
// } | ||
// }) | ||
// it('update test', async () => { | ||
// try { | ||
// var response = await makeTeams(org_uid, team_uid).fetch() | ||
// .then((team) => { | ||
// team.name = 'updated' | ||
// console.log('tttt', team) | ||
// return response.update() | ||
// }) | ||
// // const res = response.update() | ||
// console.log('update', response) | ||
// // console.log('update12', res) | ||
// } catch (err) { | ||
// console.log(err) | ||
// } | ||
// }) | ||
}) | ||
|
||
function makeTeams (org_uid, team_uid = null) { | ||
return client.organization(org_uid).teams(team_uid) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,104 @@ | ||
import Axios from 'axios' | ||
import { expect } from 'chai' | ||
import { describe, it } from 'mocha' | ||
import MockAdapter from 'axios-mock-adapter' | ||
import { Teams } from '../../lib/organization/team' | ||
import { systemUidMock, teamsMock, noticeMock } from './mock/objects' | ||
|
||
describe('Contentstack Team test', () => { | ||
it('team create test', done => { | ||
var mock = new MockAdapter(Axios) | ||
mock.onPost(`/organizations/organization_uid/teams`).reply(200, { | ||
team: { | ||
...teamsMock | ||
} | ||
}) | ||
makeTeams() | ||
.create() | ||
.then((team) => { | ||
checkTeams(team) | ||
done() | ||
}) | ||
.catch(done) | ||
}) | ||
it('Team fetch test', done => { | ||
var mock = new MockAdapter(Axios) | ||
mock.onGet(`/organizations/organization_uid/teams/UID`).reply(200, { | ||
team: { | ||
...teamsMock | ||
} | ||
}) | ||
makeTeams({ | ||
team: { | ||
...systemUidMock | ||
} | ||
}) | ||
.fetch() | ||
.then((team) => { | ||
console.log('fetch', team) | ||
checkTeams(team) | ||
done() | ||
}) | ||
.catch(done) | ||
}) | ||
it('Teams query test', done => { | ||
var mock = new MockAdapter(Axios) | ||
mock.onGet(`/organizations/organization_uid/teams`).reply(200, { | ||
teams: [ | ||
teamsMock | ||
] | ||
}) | ||
makeTeams() | ||
.query() | ||
.then((teams) => { | ||
console.log(teams) | ||
checkTeams(teams.items[0]) | ||
done() | ||
}) | ||
.catch(done) | ||
}) | ||
it('Team update test', done => { | ||
var mock = new MockAdapter(Axios) | ||
mock.onPut(`/organizations/organization_uid/teams/UID`).reply(200, { | ||
team: { | ||
...teamsMock | ||
} | ||
}) | ||
makeTeams({ | ||
team: { | ||
...systemUidMock | ||
} | ||
}) | ||
.update() | ||
.then((team) => { | ||
checkTeams(team) | ||
done() | ||
}) | ||
.catch(done) | ||
}) | ||
it('team delete test', done => { | ||
var mock = new MockAdapter(Axios) | ||
mock.onDelete(`/organizations/organization_uid/teams/UID`).reply(200, { | ||
...noticeMock | ||
}) | ||
makeTeams({ | ||
team: { | ||
...systemUidMock | ||
} | ||
}) | ||
.delete() | ||
.then((team) => { | ||
expect(team.notice).to.be.equal(noticeMock.notice) | ||
done() | ||
}) | ||
.catch(done) | ||
}) | ||
}) | ||
|
||
function makeTeams (data = {}) { | ||
return new Teams(Axios, { organization_uid: 'organization_uid', ...data }) | ||
} | ||
|
||
function checkTeams (teams) { | ||
expect(teams.name).to.be.equal('name') | ||
} |