Skip to content

Commit

Permalink
test(marshalls): fix baseMarshall unit tests (lirantal#28)
Browse files Browse the repository at this point in the history
  • Loading branch information
gagyibenedek authored and lirantal committed Apr 19, 2018
1 parent d41f0b6 commit 578cba5
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 20 deletions.
16 changes: 7 additions & 9 deletions __tests__/marshalls.base.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,18 +22,18 @@ test('checkPackage returns validation data if it was a success', async () => {
}
}

testMarshall.checkPackage('express', ctx, {})
.then(data => {
expect(data).toEqual('validation-result')
})
const result = await testMarshall.checkPackage('express', ctx, {})
expect(result).toEqual('validation-result')
})

test('checkPackage sets the error property if the validaiton failed', async () => {
const testMarshall = new TestMarshall({
packageRepoUtils: null
})

const pkg = 'trojan'
const pkg = {
packageString: 'trojan'
}
const ctx = {
marshalls: {
[TEST_MARSHALL_NAME]: {
Expand All @@ -43,10 +43,8 @@ test('checkPackage sets the error property if the validaiton failed', async () =
}

testMarshall.init(ctx)
testMarshall.checkPackage(pkg, ctx, {})
.then(data => {
expect(ctx.marshalls[TEST_MARSHALL_NAME].errors[0].pkg).toEqual(pkg)
})
await testMarshall.checkPackage(pkg, ctx, {})
expect(ctx.marshalls[TEST_MARSHALL_NAME].errors[0].pkg).toEqual(pkg.packageString)
})

test('base marshall implemented isEnabled', async () => {
Expand Down
22 changes: 11 additions & 11 deletions lib/marshalls/baseMarshall.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,19 +26,19 @@ class BaseMarshall {

checkPackage (pkg, ctx, task) {
return this.validate(pkg)
.then(data => {
task.output = `querying ${pkg.packageString}...`
ctx.marshalls[this.name].data[pkg.packageString] = data
.then(data => {
task.output = `querying ${pkg.packageString}...`
ctx.marshalls[this.name].data[pkg.packageString] = data

// not explicitly required, but a task can return its results
return data
})
.catch(err => {
this.setError({
pkg: pkg.packageString,
message: err.message
// not explicitly required, but a task can return its results
return data
})
.catch(err => {
this.setError({
pkg: pkg.packageString,
message: err.message
})
})
})
}

isEnabled (ctx) {
Expand Down

0 comments on commit 578cba5

Please sign in to comment.