• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

CenterForOpenScience / ember-osf-web / 8572628743

05 Apr 2024 04:09PM UTC coverage: 65.858% (-2.3%) from 68.147%
8572628743

Pull #2185

github

web-flow
Merge 8cf5772d8 into f8c2d0077
Pull Request #2185: [DRAFT] [ENG-5346] Added the public preregistration to the author assertions page

2642 of 4314 branches covered (61.24%)

Branch coverage included in aggregate %.

14 of 288 new or added lines in 23 files covered. (4.86%)

20 existing lines in 4 files now uncovered.

6156 of 9045 relevant lines covered (68.06%)

217.4 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

83.02
/app/adapters/contributor.ts
1
import Store from '@ember-data/store';
2
import { assert } from '@ember/debug';
3
import { inject as service } from '@ember/service';
4
import DS from 'ember-data';
5

6
import pathJoin from 'ember-osf-web/utils/path-join';
7
import OsfAdapter from './osf-adapter';
8

9
export default class ContributorAdapter extends OsfAdapter {
10
    @service store!: Store;
11

12
    buildURL(
13
        modelName?: string | number,
14
        id?: string,
15
        snapshot?: DS.Snapshot | null,
16
        requestType?: string,
17
    ) {
18
        if (requestType === 'findRecord') {
21✔
19
            const [objectId, userId] = (id || '').split('-');
1!
20
            const node = this.store.peekRecord('node', objectId);
1✔
21
            const preprint = this.store.peekRecord('preprint', objectId);
1✔
22
            const draft = this.store.peekRecord('draft-registration', objectId);
1✔
23
            let baseUrl;
24
            assert(`"contributorId" must be "objectId-userId": got ${objectId}-${userId}`, Boolean(objectId && userId));
1✔
25
            if (node) {
1!
UNCOV
26
                baseUrl = this.buildRelationshipURL((node as any)._internalModel.createSnapshot(), 'contributors');
×
27
            } else if (preprint) {
1!
NEW
UNCOV
28
                baseUrl = this.buildRelationshipURL((preprint as any)._internalModel.createSnapshot(), 'contributors');
×
29
            } else {
30
                baseUrl = this.buildRelationshipURL((draft as any)._internalModel.createSnapshot(), 'contributors');
1✔
31
            }
32
            return pathJoin(baseUrl, userId);
1✔
33
        }
34

35
        if (snapshot && requestType === 'createRecord') {
20✔
36
            const node = snapshot.belongsTo('node');
4✔
37
            const preprint = snapshot.belongsTo('preprint');
4✔
38
            const draftRegistration = snapshot.belongsTo('draftRegistration');
4✔
39
            const user = snapshot.belongsTo('users');
4✔
40
            assert('"node" or "draftRegistration" or "preprint" relationship is needed to create a contributor',
4✔
41
                Boolean(node || draftRegistration || preprint));
6!
42
            assert('"users" relationship, "email" or "fullName" is needed to create a contributor',
4✔
43
                Boolean(user || snapshot.attr('email') || snapshot.attr('fullName')));
5!
44
            let baseUrl;
45

46
            if (preprint) {
4!
47
                // if preprint relationship is defined
48
                // we post to v2/preprints/<preprint_id>/contributors
NEW
UNCOV
49
                baseUrl = this.buildRelationshipURL(preprint, 'contributors');
×
50
            }
51

52
            if (node) {
4✔
53
                // if node relationship is defined
54
                // we post to v2/nodes/<node_id>/contributors
55
                baseUrl = this.buildRelationshipURL(node, 'contributors');
2✔
56
            }
57

58
            if (draftRegistration) {
4✔
59
                // if draftRegistration relationship is defined
60
                // we post to v2/draft_registrations/<draft_id>/contributors
61
                baseUrl = this.buildRelationshipURL(draftRegistration, 'contributors');
2✔
62
            }
63
            return `${baseUrl}`;
4✔
64
        }
65
        return super.buildURL(modelName, id, snapshot, requestType);
16✔
66
    }
67
}
68

69
declare module 'ember-data/types/registries/adapter' {
70
    export default interface AdapterRegistry {
71
        contributor: ContributorAdapter;
72
    } // eslint-disable-line semi
73
}
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2025 Coveralls, Inc