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

sender usage updates #2958

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
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
11 changes: 7 additions & 4 deletions app/components/plan-usage.js
Original file line number Diff line number Diff line change
Expand Up @@ -61,10 +61,11 @@ export default Component.extend({

summarizedUsers: computed('summarizedOwnerCalculations.users', function () {
let users = [];
for (let userId in this.summarizedCalculations.users) {
const user = this.summarizedCalculations.users[userId];
if (typeof user === 'object')
for (let userId in this.summarizedOwnerCalculations.users) {
const user = this.summarizedOwnerCalculations.users[userId];
if (typeof user === 'object') {
users.push(user);
}
}
return users;
}),
Expand Down Expand Up @@ -125,7 +126,9 @@ export default Component.extend({
login: sender.login,
name: sender.name,
buildMinutes: minutes,
buildCredits: credits
buildCredits: credits,
internal: sender.internal,
provider: sender.vcs_type?.replace('User', '')?.toLowerCase()
};
}
});
Expand Down
10 changes: 7 additions & 3 deletions app/templates/components/plan_usage.hbs
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@
</table>

{{#if this.isOrganization }}
<table class="repository-build-times">
<table class="repository-build-times" data-test-sender-build-times >
<thead>
<tr data-test-table-header-row='true'>
<th>User</th>
Expand All @@ -101,13 +101,17 @@
</thead>
<tbody>
{{#each this.summarizedUsers as |user|}}
<tr data-test-repository='true'>
<tr data-test-usage-sender>
<td>
{{#if user.internal}}
{{user.login}}
{{else}}
<LinkTo
@route="user" @models={{array user}}
@route="owner" @models={{array user.provider user.login}}
>
{{user.login}}
</LinkTo>
{{/if}}
</td>
<td class='credits-row'>
{{format-number user.buildCredits}}
Expand Down
40 changes: 40 additions & 0 deletions mirage/config.js
Original file line number Diff line number Diff line change
Expand Up @@ -440,6 +440,46 @@ function routes() {
secure_user_hash: 'hash',
},
},
{
credits_consumed: 0,
minutes_consumed: 1,
sender_id: 0,
sender: {
'@type': 'user',
'@href': '/user/1',
'@representation': 'standard',
'@permissions': {
read: true,
sync: false,
},
id: 1,
login: 'cron',
name: '',
internal: true,
github_id: 1,
vcs_id: '1',
vcs_type: 'GithubUser',
avatar_url: 'https://avatars0.githubusercontent.com/u/1?v=4',
education: false,
allow_migration: false,
allowance: {
'@type': 'allowance',
'@representation': 'minimal',
subscription_type: 1,
public_repos: true,
private_repos: false,
concurrency_limit: 1,
user_usage: false,
pending_user_licenses: false,
id: 1,
},
email: null,
is_syncing: false,
synced_at: '2020-10-27T19:30:19Z',
recently_signed_up: false,
secure_user_hash: 'hash',
},
},
],
};
return response;
Expand Down
38 changes: 37 additions & 1 deletion tests/acceptance/profile/plan-usage-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import { setupApplicationTest } from 'travis/tests/helpers/setup-application-tes
import profilePage from 'travis/tests/pages/profile';
import signInUser from 'travis/tests/helpers/sign-in-user';
import { setupMirage } from 'ember-cli-mirage/test-support';
import { enableFeature } from 'ember-feature-flags/test-support';

module('Acceptance | profile/plan usage', function (hooks) {
setupApplicationTest(hooks);
Expand All @@ -19,6 +20,23 @@ module('Acceptance | profile/plan usage', function (hooks) {
createSubscription: true
}
});

this.organization = this.server.create('organization', {
name: 'Org Name',
type: 'organization',
login: 'org-login',
vcs_type: 'GithubOrganization',
vcs_id: 1983,
github_id: 1983,
permissions: {
createSubscription: true,
billing_view: true,
plan_usage: true,
plan_invoices: true,
plan_view: true,
}
});
this.organization.save();
this.server.create('allowance', {subscription_type: 2, publicRepos: true, privateRepos: true});

signInUser(this.user);
Expand Down Expand Up @@ -53,16 +71,34 @@ module('Acceptance | profile/plan usage', function (hooks) {
]
});

this.v2OrgSubscription = this.server.create('v2-subscription', {
owner: this.organization,
status: 'subscribed',
valid_to: new Date(),
addons: [
{name: 'User license addon', type: 'user_license', current_usage: {addon_usage: 1}},
{name: 'Private credit addon', type: 'credit_private', current_usage: {addon_usage: 60}}
]
});

const account = { id: 1, hasSubscriptionPermissions: true, type: 'Organization' };
this.setProperties({
account,
});
});

test('view plan usage', async function (assert) {
test('view user plan usage', async function (assert) {
await profilePage.visit();
await profilePage.planUsage.visit();
assert.equal(profilePage.planUsage.page.minutesTotal.text, 'All repositories total build time: 6 minutes');
});

test('view organization plan usage', async function (assert) {
enableFeature('github-apps');
enableFeature('proVersion');
await profilePage.visitOrganization({ name: 'org-login' });
await profilePage.planUsage.visit();
assert.equal(profilePage.planUsage.page.minutesTotal.text, 'All repositories total build time: 6 minutes');
assert.equal(profilePage.planUsage.page.senders.items[1].login, 'cron');
});
});
27 changes: 7 additions & 20 deletions tests/pages/profile.js
Original file line number Diff line number Diff line change
Expand Up @@ -809,29 +809,16 @@ export default create({
planUsage: {
visit: clickable('li[data-test-plan-usage-tab] a'),
page: {
uniquUsers: {
scope: '[data-test-user-usage-unique-users]',
text: text()
},
macMinutes: {
scope: '.data-test-plan-usage-os-icon-mac-minutes',
text: text()
},
windowsMinutes: {
scope: '.data-test-plan-usage-os-icon-windows-minutes',
text: text()
},
linuxMinutes: {
scope: '.data-test-plan-usage-os-icon-linux-minutes',
text: text()
},
creditsTotal: {
scope: '[data-test-plan-usage-credits-total]',
text: text()
},
minutesTotal: {
scope: '[data-test-plan-usage-minutes-total]',
text: text()
},
senders: {
scope: '[data-test-sender-build-times]',
items: collection('[data-test-usage-sender]', {
login: text('td', { at: 0 }),
credits: text('td', { at: 1 }),
})
}
},
checkUserActivity: {
Expand Down