Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: remove atom-space-pen-view #468

Merged
merged 11 commits into from
Feb 7, 2020
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
create client mock
  • Loading branch information
UziTech committed Feb 7, 2020
commit 8e4454f03fce48588359042ffd906ee66875ff7c
3 changes: 0 additions & 3 deletions lib/sync-settings.js
Original file line number Diff line number Diff line change
Expand Up @@ -219,12 +219,9 @@ module.exports = {

atom.config.set('sync-settings._lastBackupHash', res.data.history[0].version)
atom.notifications.addSuccess(`sync-settings: Your settings were successfully backed up. <br/><a href="${res.data.html_url}">Click here to open your Gist.</a>`)

return res.data
} catch (err) {
console.error('error backing up data: ' + err.message, err)
atom.notifications.addError(`sync-settings: Error backing up your settings. (${this._gistIdErrorMessage(err)})`)
throw err
}
},

Expand Down
93 changes: 93 additions & 0 deletions spec/create-client-mock.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,93 @@

let nonce = 0
const gists = {}

module.exports = {
gists: {
async get ({ gist_id }) {
console.debug('GITHUB_TOKEN does not exist. Mocking API calls.')

if (!(gist_id in gists)) {
throw new Error('Not Found')
}

return {
data: gists[gist_id]
}
},

async update ({ gist_id, description, files }) {
console.debug('GITHUB_TOKEN does not exist. Mocking API calls.')

if (!(gist_id in gists)) {
throw new Error('Not Found')
}

const gist = gists[gist_id]
gist.description = description
for (const filename in files) {
const file = files[filename]
if (file.filename === null) {
delete gist.files[filename]
} else if (filename in gist.files) {
gist.files[filename].content = file.content
} else {
gist.files[filename] = {
content: file.content,
filename
}
}
}
gist.history.unshift({ version: `${gist.id}-${++gist.nonce}` })

return {
data: gist
}
},

async fork ({ gist_id }) {
console.debug('GITHUB_TOKEN does not exist. Mocking API calls.')

if (!(gist_id in gists)) {
throw new Error('Not Found')
}

return this.create({
description: gists[gist_id].description,
files: gists[gist_id].files
})
},

async create ({ description, files }) {
console.debug('GITHUB_TOKEN does not exist. Mocking API calls.')

const gist_id = `mock-${nonce++}`
const gist = {
id: gist_id,
nonce: 0,
description,
files: {},
history: [{ version: `${gist_id}-0` }],
html_url: `https://${gist_id}`
}
for (const filename in files) {
const file = files[filename]
gist.files[filename] = {
constent: file.content,
filename
}
}
gists[gist_id] = gist

return {
data: gist
}
},

async delete ({ gist_id }) {
console.debug('GITHUB_TOKEN does not exist. Mocking API calls.')

delete gists[gist_id]
}
}
}
20 changes: 14 additions & 6 deletions spec/sync-settings-spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -41,14 +41,22 @@ describe('SyncSettings', () => {
})

describe('high-level', () => {
const TOKEN_CONFIG = 'sync-settings.personalAccessToken'
const GIST_ID_CONFIG = 'sync-settings.gistId'
beforeAll(async () => {
SyncSettings.activate()

SyncSettings.activate()
// wait for package to activate
await new Promise(resolve => setImmediate(resolve))

if (!process.env.GITHUB_TOKEN) {
console.error('GITHUB_TOKEN does not exist. Mocking API calls.')
const createClient = require('./create-client-mock')
spyOn(SyncSettings, 'createClient').and.returnValue(createClient)
}
})

beforeEach(async () => {
this.token = process.env.GITHUB_TOKEN || atom.config.get(TOKEN_CONFIG)
atom.config.set(TOKEN_CONFIG, this.token)
this.token = process.env.GITHUB_TOKEN || atom.config.get('sync-settings.personalAccessToken')
atom.config.set('sync-settings.personalAccessToken', this.token)

const gistSettings = {
public: false,
Expand All @@ -60,7 +68,7 @@ describe('SyncSettings', () => {

this.gistId = res.data.id
console.log(`Using Gist ${this.gistId}`)
atom.config.set(GIST_ID_CONFIG, this.gistId)
atom.config.set('sync-settings.gistId', this.gistId)
})

afterEach(async () => {
Expand Down