Skip to content

Commit

Permalink
fix: import keyword in import.js message
Browse files Browse the repository at this point in the history
  • Loading branch information
Kavya-24 committed Jul 4, 2022
1 parent c3beecd commit abc15f9
Show file tree
Hide file tree
Showing 3 changed files with 42 additions and 112 deletions.
2 changes: 1 addition & 1 deletion src/commands/alias/import.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ class Import extends AliasBaseCommand {
const destFile = args.dest
const ans = new FileUtil(this).copyFileToDestination(destFile, aliasFilePath, 'import')

if (ans) { console.log(`Successfully exported aliases to the file ${destFile}`) }
if (ans) { console.log(`Successfully imported aliases from the file ${destFile}`) }
} else {
new FileUtil(this).setupIncompleteWarning()
}
Expand Down
4 changes: 2 additions & 2 deletions test/commands/import.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ describe('Tests for importing alias', () => {
expect(await FileUtil.storage.load()).to.eql({

})
expect(ctx.stdout).to.contain(`Successfully exported aliases to the file ${filename}`)
expect(ctx.stdout).to.contain(`Successfully imported aliases from the file ${filename}`)
})

after(async function () {
Expand Down Expand Up @@ -111,7 +111,7 @@ describe('Tests for importing alias', () => {
alist: 'alias:list',
hello: 'world'
})
expect(ctx.stdout).to.contain(`Successfully exported aliases to the file ${filename}`)
expect(ctx.stdout).to.contain(`Successfully imported aliases from the file ${filename}`)
})

after(async function () {
Expand Down
148 changes: 39 additions & 109 deletions test/commands/list.test.js
Original file line number Diff line number Diff line change
@@ -1,151 +1,81 @@
const { expect, test } = require('@oclif/test')
const MemoryStorage = require('../../src/utilities/FileSnapshot/MemoryStorage.js')
const Import = require('../../src/commands/alias/import')
const List = require('../../src/commands/alias/list.js')
const FileUtil = require('../../src/utilities/FileUtility')
const fs = require('fs')

describe('Tests for importing alias', () => {
describe('Tests for listing alias', () => {
describe('Before Setup', () => {
describe('Importing an empty file', () => {
const filename = 'dataexport1.json'

describe('Listing an empty list', () => {
test
.stdout()
.stub(Import, 'storage', new MemoryStorage({}, false))
.stub(List, 'storage', new MemoryStorage({}, false))
.stub(FileUtil, 'storage', new MemoryStorage({}, false))
.command(['alias:import', `${filename}`])
.it('should throw chalk error', async _ctx => {
expect(await FileUtil.storage.load()).to.eql({
})
})
})
.command(['alias:list'])
.it('should throw the chalk error', async _ctx => {
expect(await List.storage.load()).to.eql({

describe('Importing with invalid file path', () => {
test
.stdout()
.stub(Import, 'storage', new MemoryStorage({}, false, false))
.stub(FileUtil, 'storage', new MemoryStorage({}, false, false))
.command(['alias:import', 'hsagfhb.sahdg'])
.it('should throw error that file does not exist', async ctx => {
expect(await FileUtil.storage.load()).to.eql({
})
expect(ctx.stdout).to.contain('alias file does not exist at the specified path')
})
})

describe('Importing without file path', () => {
describe('Listing with extra arguments', () => {
test
.stdout()
.stub(Import, 'storage', new MemoryStorage({}, false))
.stub(List, 'storage', new MemoryStorage({}, false))
.stub(FileUtil, 'storage', new MemoryStorage({}, false))
.command(['alias:import'])
.it('should throw error that file path not provided', async ctx => {
expect(await FileUtil.storage.load()).to.eql({
.command(['alias:list', 'hello'])
.it('should throw warning for extra argument', async ctx => {
expect(await List.storage.load()).to.eql({
})
expect(ctx.stdout).to.contain('please add the path of the alias.json file')
expect(ctx.stdout).to.contain("Invalid argument 'hello' provided")
})
})
})

describe('After Setup', () => {
describe('Importing an empty file', () => {
const filename = 'dataexport1.json'
const path = process.cwd() + '/' + filename

before(async function () {
const db = {
}

fs.writeFile(path, JSON.stringify(db), err => {
if (err) {
console.log(err)
}
})
})

describe('Listing a filled list', () => {
test
.stdout()
.stub(Import, 'storage', new MemoryStorage({}))
.stub(FileUtil, 'storage', new MemoryStorage({}))
.command(['alias:import', `${filename}`])
.it('import empty file', async ctx => {
expect(await FileUtil.storage.load()).to.eql({

.stub(List, 'storage', new MemoryStorage({ hello: 'world', alist: 'alias:list' }))
.stub(FileUtil, 'storage', new MemoryStorage({ hello: 'world', alist: 'alias:list' }))
.command(['alias:list'])
.it('should list the filled aliases list', async ctx => {
expect(await List.storage.load()).to.eql({
hello: 'world',
alist: 'alias:list'
})
expect(ctx.stdout).to.contain(`Successfully exported aliases to the file ${filename}`)
})

after(async function () {
fs.unlink(path, err => {
if (err) {
console.log(err)
}
expect(ctx.stdout).to.contain('List of the stored aliases\n')
expect(ctx.stdout).to.contain('Alias\tCommand\nhello\tworld\nalist\talias:list')
})
})
})

describe('Importing file with data', () => {
const filename = 'dataexport2.json'
const path = process.cwd() + '/' + filename

before(async function () {
const db = {
alist: 'alias:list',
hello: 'world'
}

fs.writeFile(path, JSON.stringify(db), err => {
if (err) {
console.log(err)
}
})
})

describe('Listing an empty list', () => {
test
.stdout()
.stub(Import, 'storage', new MemoryStorage({}))
.stub(List, 'storage', new MemoryStorage({}))
.stub(FileUtil, 'storage', new MemoryStorage({}))
.command(['alias:import', `${filename}`])
.it('import file with data', async ctx => {
expect(await FileUtil.storage.load()).to.eql({
alist: 'alias:list',
hello: 'world'
})
expect(ctx.stdout).to.contain(`Successfully exported aliases to the file ${filename}`)
})
.command(['alias:list'])
.it('should list the empty aliases list', async ctx => {
expect(await List.storage.load()).to.eql({

after(async function () {
fs.unlink(path, err => {
if (err) {
console.log(err)
}
})
})
})

describe('Importing with invalid file path', () => {
test
.stdout()
.stub(Import, 'storage', new MemoryStorage({}, true, false))
.stub(FileUtil, 'storage', new MemoryStorage({}, true, false))
.command(['alias:import', 'hsagfhb.sahdg'])
.it('should throw error that file does not exist', async ctx => {
expect(await FileUtil.storage.load()).to.eql({
})
expect(ctx.stdout).to.contain('alias file does not exist at the specified path')
expect(ctx.stdout).to.contain('List of the stored aliases\n')
expect(ctx.stdout).to.contain('Alias\tCommand')
})
})

describe('Importing without file path', () => {
describe('Listing with extra arguments', () => {
test
.stdout()
.stub(Import, 'storage', new MemoryStorage({}))
.stub(FileUtil, 'storage', new MemoryStorage({}))
.command(['alias:import'])
.it('should throw error that file path not provided', async ctx => {
expect(await FileUtil.storage.load()).to.eql({
.stub(List, 'storage', new MemoryStorage({ hello: 'world', alist: 'alias:list' }))
.stub(FileUtil, 'storage', new MemoryStorage({ hello: 'world', alist: 'alias:list' }))
.command(['alias:list', 'hello'])
.it('should throw warning for extra argument', async ctx => {
expect(await List.storage.load()).to.eql({
hello: 'world',
alist: 'alias:list'
})
expect(ctx.stdout).to.contain('please add the path of the alias.json file')
expect(ctx.stdout).to.contain("Invalid argument 'hello' provided")
})
})
})
Expand Down

0 comments on commit abc15f9

Please sign in to comment.