-
Notifications
You must be signed in to change notification settings - Fork 605
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
[2302] put internal-session into DI system #2315
Merged
BobrImperator
merged 1 commit into
mainmatter:master
from
BobrImperator:2302-use-di-part-2
Aug 26, 2021
+65
−130
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
5 changes: 0 additions & 5 deletions
5
packages/ember-simple-auth/addon/initializers/setup-session-service.js
This file was deleted.
Oops, something went wrong.
7 changes: 1 addition & 6 deletions
7
packages/ember-simple-auth/addon/initializers/setup-session.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,16 +1,11 @@ | ||
import Ember from 'ember'; | ||
import InternalSession from '../internal-session'; | ||
import Ephemeral from '../session-stores/ephemeral'; | ||
import inject from '../utils/inject'; | ||
|
||
export default function setupSession(registry) { | ||
registry.register('session:main', InternalSession); | ||
|
||
let store = 'session-store:application'; | ||
if (Ember.testing) { | ||
store = 'session-store:test'; | ||
registry.register(store, Ephemeral); | ||
registry.register('session-store:test', Ephemeral); | ||
} | ||
|
||
inject(registry, 'session:main', 'store', store); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
12 changes: 3 additions & 9 deletions
12
packages/ember-simple-auth/tests/unit/initializers/setup-session-service-test.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,27 +1,21 @@ | ||
import { describe, beforeEach, it } from 'mocha'; | ||
import { expect } from 'chai'; | ||
import sinonjs from 'sinon'; | ||
import setupSessionService from 'ember-simple-auth/initializers/setup-session-service'; | ||
import { setupTest } from 'ember-mocha'; | ||
|
||
describe('setupSessionService', () => { | ||
setupTest(); | ||
let sinon; | ||
let registry; | ||
|
||
beforeEach(function() { | ||
sinon = sinonjs.createSandbox(); | ||
registry = { | ||
injection() {} | ||
}; | ||
}); | ||
|
||
afterEach(function() { | ||
sinon.restore(); | ||
}); | ||
|
||
it('injects the session into the session service', function() { | ||
sinon.spy(registry, 'injection'); | ||
setupSessionService(registry); | ||
|
||
expect(registry.injection).to.have.been.calledWith('service:session', 'session', 'session:main'); | ||
expect(this.owner.lookup('service:session').session).eq(this.owner.lookup('session:main')); | ||
}); | ||
}); |
70 changes: 0 additions & 70 deletions
70
packages/ember-simple-auth/tests/unit/initializers/setup-session-test.js
This file was deleted.
Oops, something went wrong.
40 changes: 40 additions & 0 deletions
40
packages/ember-simple-auth/tests/unit/internal-session-store-test.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
import Ember from 'ember'; | ||
import { describe, beforeEach, it } from 'mocha'; | ||
import { setupApplicationTest } from 'ember-mocha'; | ||
import { expect } from 'chai'; | ||
import sinonjs from 'sinon'; | ||
|
||
describe('InternalSession store injection', () => { | ||
setupApplicationTest(); | ||
|
||
let sinon; | ||
let session; | ||
|
||
beforeEach(function() { | ||
sinon = sinonjs.createSandbox(); | ||
}); | ||
|
||
afterEach(function() { | ||
sinon.restore(); | ||
}); | ||
|
||
describe('session store injection', function() { | ||
afterEach(function() { | ||
Ember.testing = true; // eslint-disable-line ember/no-ember-testing-in-module-scope | ||
}); | ||
|
||
it('looks up the test session store when Ember.testing true', function() { | ||
Ember.testing = true; // eslint-disable-line ember/no-ember-testing-in-module-scope | ||
|
||
session = this.owner.lookup('session:main'); | ||
expect(session.get('store')).to.eql(this.owner.lookup('session-store:test')); | ||
}); | ||
|
||
it('looks up the application session store when Ember.testing false', function() { | ||
Ember.testing = false; // eslint-disable-line ember/no-ember-testing-in-module-scope | ||
|
||
session = this.owner.lookup('session:main'); | ||
expect(session.get('store')).to.eql(this.owner.lookup('session-store:application')); | ||
}); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,16 +1,12 @@ | ||
import Ember from 'ember'; | ||
import ObjectProxy from '@ember/object/proxy'; | ||
import Service from '@ember/service'; | ||
import { setOwner } from '@ember/application'; | ||
import Evented from '@ember/object/evented'; | ||
import { next } from '@ember/runloop'; | ||
import EmberObject, { set } from '@ember/object'; | ||
import { registerDeprecationHandler } from '@ember/debug'; | ||
import { describe, beforeEach, it } from 'mocha'; | ||
import { setupTest } from 'ember-mocha'; | ||
import { expect } from 'chai'; | ||
import sinonjs from 'sinon'; | ||
import Session from 'ember-simple-auth/services/session'; | ||
import * as LocationUtil from 'ember-simple-auth/utils/location'; | ||
|
||
describe('SessionService', () => { | ||
|
@@ -22,20 +18,12 @@ describe('SessionService', () => { | |
|
||
beforeEach(function() { | ||
sinon = sinonjs.createSandbox(); | ||
session = ObjectProxy.extend(Evented, { | ||
init() { | ||
this._super(...arguments); | ||
this.content = {}; | ||
} | ||
}).create(); | ||
|
||
this.owner.register('authorizer:custom', EmberObject.extend({ | ||
authorize() {} | ||
})); | ||
|
||
sessionService = Session.create({ session }); | ||
setOwner(sessionService, this.owner); | ||
this.owner.register('service:session', sessionService, { instantiate: false }); | ||
sessionService = this.owner.lookup('service:session'); | ||
session = sessionService.get('session'); | ||
}); | ||
|
||
afterEach(function() { | ||
|
@@ -147,19 +135,19 @@ describe('SessionService', () => { | |
it("is read from the session's content", function() { | ||
session.set('some', 'data'); | ||
|
||
expect(sessionService.get('data')).to.eql({ some: 'data' }); | ||
expect(sessionService.get('data')).to.eql({ some: 'data', authenticated: {} }); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This is a valid change IMO since the internal-session initializes it's |
||
}); | ||
|
||
it("is written back to the session's content", function() { | ||
sessionService.set('data.some', { other: 'data' }); | ||
|
||
expect(session.content).to.eql({ some: { other: 'data' } }); | ||
expect(session.content).to.eql({ some: { other: 'data' }, authenticated: {} }); | ||
}); | ||
|
||
it('can be set with Ember.set', function() { | ||
set(sessionService, 'data.emberSet', 'ember-set-data'); | ||
|
||
expect(session.content).to.eql({ emberSet: 'ember-set-data' }); | ||
expect(session.content).to.eql({ emberSet: 'ember-set-data', authenticated: {} }); | ||
}); | ||
|
||
it('is read-only', function() { | ||
|
@@ -325,7 +313,7 @@ describe('SessionService', () => { | |
it("does not set the session's 'attemptedTransition' property", function() { | ||
sessionService.requireAuthentication(null, 'login'); | ||
|
||
expect(sessionService.get('attemptedTransition')).to.be.undefined; | ||
expect(sessionService.get('attemptedTransition')).to.be.null; | ||
}); | ||
|
||
it('does not set the redirectTarget cookie in fastboot', function() { | ||
|
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It didn't make sense to me since there's only 1
session:main
in the app anyway? Which is even more true with us only looking it up once in session service.