Skip to content

Commit e19deba

Browse files
committed
fix oauth test file
1 parent 1fca47d commit e19deba

File tree

1 file changed

+50
-47
lines changed

1 file changed

+50
-47
lines changed

packages/oauth/__tests__/accounts-oauth.ts

Lines changed: 50 additions & 47 deletions
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ describe('AccountsOauth', () => {
6363
}
6464
});
6565

66-
it('should call provider\'s authenticate method in order to get the user itself', async () => {
66+
it("should call provider's authenticate method in order to get the user itself", async () => {
6767
const authSpy = jest.fn(() => ({
6868
id: '312312',
6969
name: 'Mr. Anderson',
@@ -83,7 +83,7 @@ describe('AccountsOauth', () => {
8383

8484
expect(authSpy).toBeCalledWith(params);
8585
});
86-
86+
8787
it('should find a user by service id or email', async () => {
8888
const authSpy = jest.fn(() => ({
8989
id: '312312',
@@ -133,7 +133,7 @@ describe('AccountsOauth', () => {
133133
id: '34123',
134134
email: user2.email,
135135
})),
136-
}
136+
};
137137
oauth.setStore(store);
138138

139139
const params = {
@@ -149,55 +149,58 @@ describe('AccountsOauth', () => {
149149
expect(store.setService).toBeCalledWith('34123', 'facebook', user2);
150150
});
151151
});
152-
153-
it('should update the user\'s profile if logged in after change in profile', async () => {
154-
const userChanged = {
155-
id: '312312',
156-
name: 'Mr. Anderson',
157-
158-
profile: {
159-
gender: 'other',
160-
},
161-
};
162-
const authSpy = jest.fn(() => userChanged);
163-
const oauth = new AccountsOauth({
164-
facebook: {
165-
authenticate: authSpy,
166-
},
167-
});
168-
oauth.setStore(mockStore);
169-
170-
const params = {
171-
provider: 'facebook',
172-
};
173-
await oauth.authenticate(params);
174152

175-
expect(authSpy).toBeCalledWith(params);
176-
expect(mockStore.findUserByServiceId).toBeCalledWith('facebook', '312312');
177-
expect(mockStore.setProfile).toBeCalledWith(user.id, userChanged.profile);
178-
expect(mockStore.setService).toBeCalledWith(user.id, 'facebook', userChanged);
179-
});
180-
});
181-
182-
describe('unlink', () => {
153+
it("should update the user's profile if logged in after change in profile", async () => {
154+
const userChanged = {
155+
id: '312312',
156+
name: 'Mr. Anderson',
157+
158+
profile: {
159+
gender: 'other',
160+
},
161+
};
162+
const authSpy = jest.fn(() => userChanged);
183163
const oauth = new AccountsOauth({
184164
facebook: {
185-
authenticate: jest.fn(),
165+
authenticate: authSpy,
186166
},
187167
});
188168
oauth.setStore(mockStore);
189-
190-
it('should throw if given wrong provider', async () => {
191-
try {
192-
await oauth.unlink('1', 'twitter');
193-
} catch(e) {
194-
expect(e.message).toBe('Invalid provider');
195-
}
196-
});
197-
198-
it('should unset data of oauth provider', async () => {
199-
await oauth.unlink('1', 'facebook');
200-
expect(mockStore.setService).toBeCalledWith('1', 'facebook', null);
201-
});
169+
170+
const params = {
171+
provider: 'facebook',
172+
};
173+
await oauth.authenticate(params);
174+
175+
expect(authSpy).toBeCalledWith(params);
176+
expect(mockStore.findUserByServiceId).toBeCalledWith('facebook', '312312');
177+
expect(mockStore.setProfile).toBeCalledWith(user.id, userChanged.profile);
178+
expect(mockStore.setService).toBeCalledWith(
179+
user.id,
180+
'facebook',
181+
userChanged
182+
);
183+
});
184+
});
185+
186+
describe('unlink', () => {
187+
const oauth = new AccountsOauth({
188+
facebook: {
189+
authenticate: jest.fn(),
190+
},
191+
});
192+
oauth.setStore(mockStore);
193+
194+
it('should throw if given wrong provider', async () => {
195+
try {
196+
await oauth.unlink('1', 'twitter');
197+
} catch (e) {
198+
expect(e.message).toBe('Invalid provider');
199+
}
200+
});
201+
202+
it('should unset data of oauth provider', async () => {
203+
await oauth.unlink('1', 'facebook');
204+
expect(mockStore.setService).toBeCalledWith('1', 'facebook', null);
202205
});
203206
});

0 commit comments

Comments
 (0)