Skip to content

Commit

Permalink
Restored config extension to main module. Resolves #75
Browse files Browse the repository at this point in the history
  • Loading branch information
jpatel531 committed Aug 26, 2015
1 parent f66cb12 commit 4b19de0
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 19 deletions.
5 changes: 5 additions & 0 deletions lib/atom_pair.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@ Invitation = null
HipChatInvitation = null
SlackInvitation = null
Session = null
_ = null
AtomPairConfig = null

module.exports = AtomPair =

Expand All @@ -12,9 +14,12 @@ module.exports = AtomPair =
subscriptions: null

activate: (state) ->
_ = require 'underscore'
Invitation = require './modules/invitations/invitation'
HipChatInvitation = require './modules/invitations/hipchat_invitation'
SlackInvitation = require './modules/invitations/slack_invitation'
AtomPairConfig = require './modules/atom_pair_config'
_.extend(@, AtomPairConfig)

Session = require './modules/session'

Expand Down
14 changes: 0 additions & 14 deletions lib/modules/atom_pair_config.coffee
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
_ = require 'underscore'

module.exports = AtomPairConfig =

config:
Expand All @@ -23,15 +21,3 @@ module.exports = AtomPairConfig =
type: 'string'
description: 'WebHook URL for Slack Incoming Webhook Integration'
default: ''

getKeysFromConfig: ->
@app_key ?= atom.config.get 'atom-pair.pusher_app_key'
@app_secret ?= atom.config.get 'atom-pair.pusher_app_secret'
@hc_key ?= atom.config.get 'atom-pair.hipchat_token'
@room_name ?= atom.config.get 'atom-pair.hipchat_room_name'
@slack_url ?= atom.config.get 'atom-pair.slack_url'

missingPusherKeys: -> _.any([@app_key, @app_secret], @missing)
missingHipChatKeys: -> _.any([@hc_key, @room_name], @missing)
missingSlackWebHook: -> _.any([@slack_url], @missing)
missing: (key) -> key is '' || typeof(key) is "undefined"
14 changes: 12 additions & 2 deletions lib/modules/session.coffee
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
require '../pusher/pusher'
require '../pusher/pusher-js-client-auth'
{CompositeDisposable, Emitter} = require 'atom'
AtomPairConfig = require './atom_pair_config'
MessageQueue = require './message_queue'
SharePane = require './share_pane'
User = require './user'
Expand Down Expand Up @@ -34,7 +33,6 @@ class Session
session.pairingSetup()

constructor: (@id, @app_key, @app_secret)->
_.extend(@, AtomPairConfig)
@getKeysFromConfig()
@id ?= "#{@app_key}-#{@app_secret}-#{randomstring.generate(11)}"
@triggerPush = @engageTabListener = true
Expand Down Expand Up @@ -177,3 +175,15 @@ class Session
listenForDestruction: ->
SharePane.globalEmitter.on 'disconnected', =>
if (_.all SharePane.all, (pane) => !pane.connected) then @end()

getKeysFromConfig: ->
@app_key ?= atom.config.get 'atom-pair.pusher_app_key'
@app_secret ?= atom.config.get 'atom-pair.pusher_app_secret'
@hc_key ?= atom.config.get 'atom-pair.hipchat_token'
@room_name ?= atom.config.get 'atom-pair.hipchat_room_name'
@slack_url ?= atom.config.get 'atom-pair.slack_url'

missingPusherKeys: -> _.any([@app_key, @app_secret], @missing)
missingHipChatKeys: -> _.any([@hc_key, @room_name], @missing)
missingSlackWebHook: -> _.any([@slack_url], @missing)
missing: (key) -> key is '' || typeof(key) is "undefined"
7 changes: 4 additions & 3 deletions spec/user/user-spec.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ describe "User", ->

beforeEach ->
activationPromise = atom.packages.activatePackage('atom-pair')
pusher = new PusherMock
pusher = new PusherMock 'key', 'secret'
spyOn(window, 'Pusher').andReturn(pusher)
User.clear()

Expand Down Expand Up @@ -57,15 +57,16 @@ describe "User", ->

runs ->
spyOn(window, 'Date').andReturn({getTime: -> 30})

atom.config.set('atom-pair.pusher_app_key', 'key')
atom.config.set('atom-pair.pusher_app_secret', 'secret')
session = new Session
session.pairingSetup()
session.channel.fakeSend('pusher:subscription_succeeded', pusher.mockMembers(
[{id: 'red', arrivalTime: 1}]
))

expect(window.Pusher.argsForCall.length).toBe(2)
expect(window.Pusher.argsForCall).toEqual([ [ undefined, { authTransport : 'client', clientAuth : { key : undefined, secret : undefined, user_id : 'blank', user_info : { arrivalTime : 'blank' } } } ], [ undefined, { authTransport : 'client', clientAuth : { key : undefined, secret : undefined, user_id : 'blue', user_info : { arrivalTime : 30 } } } ] ])
expect(window.Pusher.argsForCall).toEqual([ [ 'key', { authTransport : 'client', clientAuth : { key : 'key', secret : 'secret', user_id : 'blank', user_info : { arrivalTime : 'blank' } } } ], [ 'key', { authTransport : 'client', clientAuth : { key : 'key', secret : 'secret', user_id : 'blue', user_info : { arrivalTime : 30 } } } ] ])
expect(User.all.length).toBe(2)
expect(User.me.isLeader()).toBe(false)
expect(User.me.colour).not.toBe('red')
Expand Down

0 comments on commit 4b19de0

Please sign in to comment.