Skip to content
This repository has been archived by the owner on Oct 26, 2023. It is now read-only.

Commit

Permalink
test(fetchToken): add test
Browse files Browse the repository at this point in the history
  • Loading branch information
Abimbola Idowu committed Mar 12, 2017
1 parent a6d842e commit 443d7f9
Show file tree
Hide file tree
Showing 5 changed files with 50 additions and 4 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@
"eslint-plugin-react": "^6.3.0",
"ghooks": "^1.3.2",
"nyc": "^8.1.0",
"rimraf": "^2.5.4",
"rimraf": "^2.6.1",
"sinon": "^1.17.6",
"streamtest": "^1.2.2",
"tap-spec": "^4.1.1",
Expand Down
3 changes: 3 additions & 0 deletions src/cli.js
Original file line number Diff line number Diff line change
Expand Up @@ -112,3 +112,6 @@ else if (args.channel)
slackHistoryExport.processChannels(args.filepath)
.then(successCallback)
.catch(errorCallback)
else
log.error('Error:', 'Export type not suppported')

13 changes: 13 additions & 0 deletions test/integration/cli.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,19 @@ test(`CLI
})
})

test(`CLI
should export slack im history`, (t) => {
exec(`${binPath} -t ${SLACK_API_TOKEN}`,
(error, stdout, stderr) => {
t.false(error, 'returns no error')
t.ok(
/Export type not suppported/.test(stderr),
'Should throw an error when an no type is passed'
)
t.end()
})
})

test(`CLI
should error export slack im history`, (t) => {
const fileObj = tmp.fileSync()
Expand Down
24 changes: 24 additions & 0 deletions test/utils.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import {
getUserIMInfo,
getGroupInfo,
getChannelInfo,
fetchToken,
} from 'utils'

test(`getChannelInfo
Expand Down Expand Up @@ -203,3 +204,26 @@ test(`getUserIMInfo
t.end()
})
})

test(`fetchToken
should return token if passed in`, (t) => {
const token = 'testingToken'
const result = fetchToken(token)
const message = 'Passed in token is returned'
t.equal(token, result, message)
t.end()
})

test(`fetchToken
should fetch token from env var`, (t) => {
const token = 'testingToken'
// Store old value, so can be restored
const oldEnvVar = process.env.SLACK_HISTORY_EXPORT_TOKEN
process.env.SLACK_HISTORY_EXPORT_TOKEN = token
const result = fetchToken()
const message = 'Token is fetched from the set env variable'
t.equal(token, result, message)
// Restore old value
process.env.SLACK_HISTORY_EXPORT_TOKEN = oldEnvVar
t.end()
})
12 changes: 9 additions & 3 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -2824,9 +2824,9 @@ right-pad@^1.0.1:
version "1.0.1"
resolved "https://registry.yarnpkg.com/right-pad/-/right-pad-1.0.1.tgz#8ca08c2cbb5b55e74dafa96bf7fd1a27d568c8d0"

rimraf@2, rimraf@^2.2.8, rimraf@^2.3.3, rimraf@^2.4.3, rimraf@^2.4.4, rimraf@^2.5.4, rimraf@~2.5.1, rimraf@~2.5.4:
version "2.5.4"
resolved "https://registry.yarnpkg.com/rimraf/-/rimraf-2.5.4.tgz#96800093cbf1a0c86bd95b4625467535c29dfa04"
rimraf@2, rimraf@^2.2.8, rimraf@^2.3.3, rimraf@^2.4.3, rimraf@^2.4.4, rimraf@^2.5.4, rimraf@^2.6.1:
version "2.6.1"
resolved "https://registry.yarnpkg.com/rimraf/-/rimraf-2.6.1.tgz#c2338ec643df7a1b7fe5c54fa86f57428a55f33d"
dependencies:
glob "^7.0.5"

Expand All @@ -2836,6 +2836,12 @@ rimraf@~2.1.4:
optionalDependencies:
graceful-fs "~1"

rimraf@~2.5.1, rimraf@~2.5.4:
version "2.5.4"
resolved "https://registry.yarnpkg.com/rimraf/-/rimraf-2.5.4.tgz#96800093cbf1a0c86bd95b4625467535c29dfa04"
dependencies:
glob "^7.0.5"

run-async@^0.1.0:
version "0.1.0"
resolved "https://registry.yarnpkg.com/run-async/-/run-async-0.1.0.tgz#c8ad4a5e110661e402a7d21b530e009f25f8e389"
Expand Down

0 comments on commit 443d7f9

Please sign in to comment.