Skip to content

Commit

Permalink
fix(test): Fix mocha tests
Browse files Browse the repository at this point in the history
  • Loading branch information
Khaledgarbaya committed Oct 17, 2018
1 parent 17f5ca4 commit 5d3b9df
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 10 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@
"prepare": "npm run build",
"test": "NOCK_RECORD=0 npm run build && npm run test-unit && npm run test-integration && npm run test-e2e && npm run lint",
"test-watch": "npm run test-unit -- --watch",
"test-unit": "NODE_ENV=test mocha --require test/setup-unit.js --recursive test/unit/lib/**/*.spec.{js,ts} ",
"test-unit": "NODE_ENV=test mocha --require test/setup-unit.js --recursive 'test/unit/lib/**/*.spec.{js,ts}' ",
"test-integration": "NODE_ENV=test mocha --require test/integration/setup.js 'test/integration/**/*.spec.js'",
"test-e2e": "NODE_ENV=test mocha 'test/end-to-end/**/*.spec.js'",
"cover-unit": "nyc npm run test-unit",
Expand Down
11 changes: 10 additions & 1 deletion src/lib/action/editorinterface-save.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,16 @@ class SaveEditorInterfaceAction extends APIAction {
}

async applyTo (api: OfflineAPI) {
await api.saveEditorInterfaces(this.contentTypeId)
try {
await api.saveEditorInterfaces(this.contentTypeId)
} catch {
// TODO: Maybe a better handling
// What the heck are you doing?
// When fetching the editor interfaces
// the offline API will always create an editor interface
// for the content type if it does not exist.
// So we shouldn't throw at the first place maybe ?
}
}
}

Expand Down
9 changes: 6 additions & 3 deletions src/lib/intent-list/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,6 @@ class IntentList {
await action.applyTo(api)
continue
}

if (action instanceof EntityAction) {
const entityType = action.getEntityType()
const entityId = action.getEntityId()
Expand All @@ -113,8 +112,12 @@ class IntentList {
await action.applyTo(ct)
}
if (entityType === 'EDITOR_INTERFACE') {
const editorInterfaces = await api.getEditorInterfaces(entityId)
await action.applyTo(editorInterfaces)
try {
const editorInterfaces = await api.getEditorInterfaces(entityId)
await action.applyTo(editorInterfaces)
} catch {
// TODO: maybe a better handling
}
}
continue
}
Expand Down
12 changes: 7 additions & 5 deletions test/unit/lib/migration-parser.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@

const { expect } = require('chai')
import createMigrationParser from '../../../src/lib/migration-parser'
// import { APIEditorInterfaces } from '../../../src/lib/interfaces/content-type'

describe('Migration parser', function () {
describe('when transforming content', function () {
Expand All @@ -19,12 +18,14 @@ describe('Migration parser', function () {
sys: { id: 'cat' },
fields: [{ name: 'name', type: 'Symbol', id: 'name' }]
}
]
],
total: 2
}
}

if (config.url === '/entries?sys.contentType.sys.id[in]=foo,cat') {
if (config.url.indexOf('/entries?sys.contentType.sys.id[in]=foo,cat') !== -1) {
return {
total: 2,
items: [
{
sys: {
Expand Down Expand Up @@ -55,7 +56,6 @@ describe('Migration parser', function () {
return {items: [{code: 'en-US'}]}
}
}

const migrationParser = createMigrationParser(fakeMakeRequest, {})

// make this something that throws the second time
Expand Down Expand Up @@ -110,6 +110,7 @@ describe('Migration parser', function () {
console.log(config.url)
if (config.url === '/content_types?sys.id[in]=foo') {
return {
total: 1,
items: [
{
sys: { id: 'foo' },
Expand All @@ -119,8 +120,9 @@ describe('Migration parser', function () {
}
}

if (config.url === '/entries?sys.contentType.sys.id[in]=foo') {
if (config.url === '/entries?sys.contentType.sys.id[in]=foo&skip=0') {
return {
total: 2,
items: [
{
sys: {
Expand Down

0 comments on commit 5d3b9df

Please sign in to comment.