-
Notifications
You must be signed in to change notification settings - Fork 29
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #365 from ademarCardoso/feature/list-spaces
Feature/list spaces
- Loading branch information
Showing
7 changed files
with
116 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
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,35 @@ | ||
const chalk = require('chalk') | ||
|
||
/** | ||
* @method listSpaces | ||
* @param api - Pass the api instance as a parameter | ||
* @return {Promise} | ||
*/ | ||
|
||
const listSpaces = async (api) => { | ||
console.log() | ||
console.log(chalk.green('✓') + ' Loading spaces...') | ||
console.log() | ||
|
||
if (!api) { | ||
console.log(chalk.red('X') + 'Api instance is required to make the request') | ||
return [] | ||
} | ||
|
||
const spaces = await api.getAllSpaces() | ||
.then(res => res) | ||
.catch(err => Promise.reject(err)) | ||
|
||
if (!spaces) { | ||
console.log(chalk.red('X') + ' No spaces were found for this user ') | ||
return [] | ||
} | ||
|
||
spaces.map(space => { | ||
console.log(`${space.name} (id: ${space.id})`) | ||
}) | ||
|
||
return spaces | ||
} | ||
|
||
module.exports = listSpaces |
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,22 @@ | ||
const { listSpaces } = require('../../src/tasks/') | ||
const { FAKE_SPACES } = require('../constants') | ||
|
||
describe('Test spaces method', () => { | ||
it('Testing list-spaces funtion without api instance', async () => { | ||
try { | ||
const spaces = await listSpaces() | ||
expect(spaces).toStrictEqual([]) | ||
} catch (e) { | ||
console.error(e) | ||
} | ||
}) | ||
it('Testing list-spaces funtion with api instance', async () => { | ||
const FAKE_API = { | ||
getAllSpaces: jest.fn(() => Promise.resolve(FAKE_SPACES())) | ||
} | ||
expect( | ||
await listSpaces(FAKE_API) | ||
).toEqual(FAKE_SPACES()) | ||
expect(FAKE_API.getAllSpaces).toHaveBeenCalled() | ||
}) | ||
}) |