Skip to content
This repository has been archived by the owner on Apr 11, 2024. It is now read-only.

Commit

Permalink
Merge pull request #1313 from Shopify/liz/only-return-user-when-online
Browse files Browse the repository at this point in the history
Only return user when online
  • Loading branch information
lizkenyon authored Apr 1, 2024
2 parents af30ecd + b60c6c9 commit 765dff6
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 20 deletions.
5 changes: 5 additions & 0 deletions .changeset/nasty-trees-sing.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@shopify/shopify-api": patch
---

Fixes bug, that is returning the onlineAccessInfo field on the session, when the session if offline
15 changes: 15 additions & 0 deletions packages/shopify-api/lib/session/__tests__/session.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -571,5 +571,20 @@ describe('toPropertyArray and fromPropertyArray', () => {
).toBeUndefined();
}
});
const describe = test.session.isOnline ? 'Does' : 'Does not';
const isOnline = test.session.isOnline ? 'online' : 'offline';

it(`${describe} have online access info when the token is ${isOnline}`, () => {
const session = new Session(test.session);
const sessionCopy = Session.fromPropertyArray(
session.toPropertyArray(test.returnUserData),
test.returnUserData,
);
if (test.session.isOnline) {
expect(sessionCopy.onlineAccessInfo).toBeDefined();
} else {
expect(sessionCopy.onlineAccessInfo).toBeUndefined();
}
});
});
});
36 changes: 16 additions & 20 deletions packages/shopify-api/lib/session/session.ts
Original file line number Diff line number Diff line change
Expand Up @@ -58,11 +58,10 @@ export class Session {
}),
);

const sessionData = {
onlineAccessInfo: {
associated_user: {},
},
} as SessionParams;
const sessionData = {} as SessionParams;
const onlineAccessInfo = {
associated_user: {},
} as OnlineAccessInfo;
Object.entries(obj).forEach(([key, value]) => {
switch (key) {
case 'isOnline':
Expand All @@ -81,59 +80,56 @@ export class Session {
sessionData[key] = value ? new Date(Number(value)) : undefined;
break;
case 'onlineAccessInfo':
sessionData.onlineAccessInfo!.associated_user.id = Number(value);
onlineAccessInfo.associated_user.id = Number(value);
break;
case 'userId':
if (returnUserData) {
sessionData.onlineAccessInfo!.associated_user.id = Number(value);
onlineAccessInfo.associated_user.id = Number(value);
break;
}
case 'firstName':
if (returnUserData) {
sessionData.onlineAccessInfo!.associated_user.first_name =
String(value);
onlineAccessInfo.associated_user.first_name = String(value);
break;
}
case 'lastName':
if (returnUserData) {
sessionData.onlineAccessInfo!.associated_user.last_name =
String(value);
onlineAccessInfo.associated_user.last_name = String(value);
break;
}
case 'email':
if (returnUserData) {
sessionData.onlineAccessInfo!.associated_user.email = String(value);
onlineAccessInfo.associated_user.email = String(value);
break;
}
case 'accountOwner':
if (returnUserData) {
sessionData.onlineAccessInfo!.associated_user.account_owner =
Boolean(value);
onlineAccessInfo.associated_user.account_owner = Boolean(value);
break;
}
case 'locale':
if (returnUserData) {
sessionData.onlineAccessInfo!.associated_user.locale =
String(value);
onlineAccessInfo.associated_user.locale = String(value);
break;
}
case 'collaborator':
if (returnUserData) {
sessionData.onlineAccessInfo!.associated_user.collaborator =
Boolean(value);
onlineAccessInfo.associated_user.collaborator = Boolean(value);
break;
}
case 'emailVerified':
if (returnUserData) {
sessionData.onlineAccessInfo!.associated_user.email_verified =
Boolean(value);
onlineAccessInfo.associated_user.email_verified = Boolean(value);
break;
}
// Return any user keys as passed in
default:
sessionData[key] = value;
}
});
if (sessionData.isOnline) {
sessionData.onlineAccessInfo = onlineAccessInfo;
}
const session = new Session(sessionData);
return session;
}
Expand Down

0 comments on commit 765dff6

Please sign in to comment.