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

Reach > 90% coverage and add Integration Testing #709

Merged
merged 37 commits into from
Jun 20, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
37 commits
Select commit Hold shift + click to select a range
5ebb351
Run node tests
jdalrymple May 15, 2020
1fd3e10
Remove typed services in tests
jdalrymple May 21, 2020
f3334a3
Skip usergpg keys for now
jdalrymple May 21, 2020
225c0ab
Reduce service initialization
jdalrymple May 22, 2020
d0ee10f
Elongate initial wait time
jdalrymple May 24, 2020
1ea0d10
Converting more tests to the core package
jdalrymple May 31, 2020
2c040c8
Moving over more tests
jdalrymple May 31, 2020
435562e
Fixing jest errors
jdalrymple May 31, 2020
5991ebe
Moving over more tests
jdalrymple May 31, 2020
92e42d2
Linting
jdalrymple May 31, 2020
744ee56
Test errors
jdalrymple May 31, 2020
17df018
More test adjustments
jdalrymple May 31, 2020
ea7dd76
More debugging
jdalrymple May 31, 2020
7f68cd8
Adjustments
jdalrymple May 31, 2020
4608fe5
Debug
jdalrymple May 31, 2020
c802bbc
Change the args
jdalrymple May 31, 2020
d5b9cf4
Change function name
jdalrymple May 31, 2020
3d900f4
Comment out test for now
jdalrymple May 31, 2020
b17a63c
Adding proper unit tests for many services
jdalrymple Jun 16, 2020
0a911ff
Cleaning up logic for the NotificationSettings API and adding unit tests
jdalrymple Jun 16, 2020
7d28a07
Set a default for the all function options
jdalrymple Jun 16, 2020
0b2cd3c
Cleaning up the logic in the MergeRequests API
jdalrymple Jun 16, 2020
746394d
More unit tests
jdalrymple Jun 17, 2020
e821011
Integration tests with module mapper
jdalrymple Jun 17, 2020
af2bb0f
Missing closing quote
jdalrymple Jun 18, 2020
9f6666d
to many quotes
jdalrymple Jun 18, 2020
380c391
Proper stringify
jdalrymple Jun 18, 2020
ec418e8
More tests
jdalrymple Jun 18, 2020
38da7b0
Added more tests
jdalrymple Jun 18, 2020
78f7557
Additional tests
jdalrymple Jun 18, 2020
84606c7
Adding a different formdata library
jdalrymple Jun 19, 2020
adf9f7a
Moving the json rollup
jdalrymple Jun 19, 2020
7bd7414
Fixing up export
jdalrymple Jun 19, 2020
670a251
File cleanup
jdalrymple Jun 19, 2020
103cf1d
Updating tests
jdalrymple Jun 19, 2020
b82a15f
switch back to old form data
jdalrymple Jun 19, 2020
8fb63a3
Adding another test
jdalrymple Jun 20, 2020
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
80 changes: 38 additions & 42 deletions .gitlab-ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -72,56 +72,52 @@ test:unit:utils:
stage: test
script: yarn jest utils/test/unit && yarn codecov -F utils

# Integration Tests
# .test:integration: &integration
# image:
# name: docker/compose:latest
# entrypoint: ['/bin/sh', '-c']
# variables:
# DOCKER_HOST: tcp://docker:2375
# GITLAB_URL: http://docker:8080
# services:
# - docker:dind
# stage: test
# before_script:
# # Install docker compose
# - apk add --no-cache nodejs yarn git

# # Spin up container
# - cd scripts
# - docker-compose -f docker-compose.yml up -d

# # Verify Gitlab instance is up and running
# - node probe.js

# # Get the personal token
# - export PERSONAL_ACCESS_TOKEN=$(docker exec -i gitlab sh -c 'gitlab-rails r /mnt/init.rb')

# - cd ..
# - echo $PERSONAL_ACCESS_TOKEN
# - echo $GITLAB_URL
# - echo $CODECOV_TOKEN
#Integration Tests
.test:integration: &integration
image:
name: docker/compose:latest
entrypoint: ['/bin/sh', '-c']
variables:
DOCKER_HOST: tcp://docker:2375
GITLAB_URL: http://docker:8080
services:
- docker:dind
stage: test
before_script:
# Install docker compose
- apk add --no-cache nodejs yarn git

# Spin up container
- cd scripts
- docker-compose -f docker-compose.yml up -d

# Verify Gitlab instance is up and running
- node probe.js

# Get the personal token
- export PERSONAL_ACCESS_TOKEN=$(docker exec -i gitlab sh -c 'gitlab-rails r /mnt/init.rb')

- cd ..
- echo $PERSONAL_ACCESS_TOKEN
- echo $GITLAB_URL
- echo $CODECOV_TOKEN

test:integration:browser:
image: buildkite/puppeteer
stage: test
script: yarn jest browser/test/integration

# test:integration:node:
# <<: *integration
# script: yarn jest node/test/integration && yarn codecov -F node

# test:cli:integration:dist:
# <<: *integration
# script: yarn jest core/test/integration --runInBand && yarn codecov
test:integration:node:src:
<<: *integration
script: yarn jest node/test/integration && yarn codecov -F node

# test:core:integration:dist-cjs:
# <<: *integration
# script: yarn jest core/test/integration --runInBand --moduleNameMapper="{dist:dist/index.es.js}"
test:integration:node:dist-cjs:
<<: *integration
script: yarn jest node/test/integration --moduleNameMapper='{"src":"<rootDir>/dist/index.js"}'

# test:core:integration:dist-es
# <<: *integration
# script: yarn jest core/test/integration --runInBand --moduleNameMapper="{dist:dist/index.es.js}"
test:integration:node:dist-es:
<<: *integration
script: yarn jest node/test/integration --moduleNameMapper='{"src":"<rootDir>/dist/index.js"}'

# Canary
canary:
Expand Down
2 changes: 1 addition & 1 deletion codecov.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ coverage:
target: 60%
flags: cli
core:
target: 60%
target: 90%
flags: core
browser:
target: 60%
Expand Down
2 changes: 1 addition & 1 deletion packages/gitbeaker-core/src/infrastructure/Utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ export interface Bundle<T extends { [name: string]: Constructor }, P extends key

export function bundler<T extends { [name: string]: Constructor }, P extends keyof T>(services: T) {
return (function Bundle(options?: any) {
Object.entries(services || {}).forEach(([name, Ser]) => {
Object.entries(services).forEach(([name, Ser]) => {
this[name] = new Ser(options);
});
} as any) as Bundle<T, P>;
Expand Down
2 changes: 1 addition & 1 deletion packages/gitbeaker-core/src/infrastructure/index.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
export * from './BaseService';
export { bundler } from './Utils';
export * from './Utils';
export * from './RequestHelper';
5 changes: 3 additions & 2 deletions packages/gitbeaker-core/src/services/BroadcastMessages.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import {
BaseService,
PaginatedRequestOptions,
RequestHelper,
Sudo,
} from '../infrastructure';

export class BroadcastMessages extends BaseService {
Expand All @@ -20,10 +21,10 @@ export class BroadcastMessages extends BaseService {
return RequestHelper.put(this, `broadcast_messages/${bId}`, options);
}

remove(broadcastMessageId: number) {
remove(broadcastMessageId: number, options?: Sudo) {
const bId = encodeURIComponent(broadcastMessageId);

return RequestHelper.del(this, `broadcast_messages/${bId}`);
return RequestHelper.del(this, `broadcast_messages/${bId}`, options);
}

show(broadcastMessageId: number, options?: BaseRequestOptions) {
Expand Down
2 changes: 1 addition & 1 deletion packages/gitbeaker-core/src/services/CommitDiscussions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ export interface CommitDiscussions extends ResourceDiscussions {
}

export class CommitDiscussions extends ResourceDiscussions {
constructor(options: BaseServiceOptions = {}) {
constructor(options: BaseServiceOptions) {
super('projects', 'commits', options);
}
}
2 changes: 1 addition & 1 deletion packages/gitbeaker-core/src/services/DeployKeys.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ export class DeployKeys extends BaseService {
return RequestHelper.post(this, `projects/${pId}/deploy_keys`, options);
}

all({ projectId, ...options }: { projectId?: string | number } & PaginatedRequestOptions) {
all({ projectId, ...options }: { projectId?: string | number } & PaginatedRequestOptions = {}) {
let url;

if (projectId) {
Expand Down
2 changes: 1 addition & 1 deletion packages/gitbeaker-core/src/services/EpicDiscussions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ export interface EpicDiscussions extends ResourceDiscussions {
}

export class EpicDiscussions extends ResourceDiscussions {
constructor(options: BaseServiceOptions = {}) {
constructor(options: BaseServiceOptions) {
super('groups', 'epics', options);
}
}
2 changes: 1 addition & 1 deletion packages/gitbeaker-core/src/services/EpicNotes.ts
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ export interface EpicNotes extends ResourceNotes {
}

export class EpicNotes extends ResourceNotes {
constructor(options: BaseServiceOptions = {}) {
constructor(options: BaseServiceOptions) {
super('groups', 'epics', options);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { ResourceTemplates } from '../templates';
import { BaseServiceOptions } from '../infrastructure';

export class GitLabCIYMLTemplates extends ResourceTemplates {
constructor(options: BaseServiceOptions = {}) {
constructor(options: BaseServiceOptions) {
super('gitlab_ci_ymls', options);
}
}
2 changes: 1 addition & 1 deletion packages/gitbeaker-core/src/services/GitignoreTemplates.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { ResourceTemplates } from '../templates';
import { BaseServiceOptions } from '../infrastructure';

export class GitignoreTemplates extends ResourceTemplates {
constructor(options: BaseServiceOptions = {}) {
constructor(options: BaseServiceOptions) {
super('gitignores', options);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { ResourceAccessRequests } from '../templates';
import { BaseServiceOptions } from '../infrastructure';

export class GroupAccessRequests extends ResourceAccessRequests {
constructor(options: BaseServiceOptions = {}) {
constructor(options: BaseServiceOptions) {
super('groups', options);
}
}
2 changes: 1 addition & 1 deletion packages/gitbeaker-core/src/services/GroupBadges.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ export interface GroupBadges extends ResourceBadges {
}

export class GroupBadges extends ResourceBadges {
constructor(options: BaseServiceOptions = {}) {
constructor(options: BaseServiceOptions) {
super('groups', options);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ export interface GroupCustomAttributes extends ResourceCustomAttributes {
}

export class GroupCustomAttributes extends ResourceCustomAttributes {
constructor(options: BaseServiceOptions = {}) {
constructor(options: BaseServiceOptions) {
super('groups', options);
}
}
51 changes: 15 additions & 36 deletions packages/gitbeaker-core/src/services/Jobs.ts
Original file line number Diff line number Diff line change
Expand Up @@ -101,19 +101,12 @@ export class Jobs extends BaseService {
projectId: string | number,
jobId: number,
artifactPath: string,
{ stream = false, ...options }: { stream?: boolean } & BaseRequestOptions,
{ stream = false, ...options }: { stream?: boolean } & BaseRequestOptions = {},
) {
const [pId, jId] = [projectId, jobId].map(encodeURIComponent);
const method = stream ? 'stream' : 'get';

if (stream) {
return RequestHelper.stream(
this,
`projects/${pId}/jobs/${jId}/artifacts/${artifactPath}`,
options,
);
}

return RequestHelper.get(
return RequestHelper[method](
this,
`projects/${pId}/jobs/${jId}/artifacts/${artifactPath}`,
options,
Expand All @@ -124,45 +117,31 @@ export class Jobs extends BaseService {
projectId: string | number,
ref: string,
artifactPath: string,
name: string,
{ stream = false, ...options }: { stream?: boolean } & BaseRequestOptions,
jobName: string,
{ stream = false, ...options }: { stream?: boolean } & BaseRequestOptions = {},
) {
const [pId, rId, jobName] = [projectId, ref, name].map(encodeURIComponent);

if (stream) {
return RequestHelper.stream(
this,
`projects/${pId}/jobs/artifacts/${rId}/raw/${artifactPath}?job=${jobName}`,
options,
);
}
const [pId, rId, name] = [projectId, ref, jobName].map(encodeURIComponent);
const method = stream ? 'stream' : 'get';

return RequestHelper.get(
return RequestHelper[method](
this,
`projects/${pId}/jobs/artifacts/${rId}/raw/${artifactPath}?job=${jobName}`,
`projects/${pId}/jobs/artifacts/${rId}/raw/${artifactPath}?job=${name}`,
options,
);
}

downloadLatestArtifactFile(
projectId: string | number,
ref: string,
name: string,
{ stream = false, ...options }: { stream?: boolean } & BaseRequestOptions,
jobName: string,
{ stream = false, ...options }: { stream?: boolean } & BaseRequestOptions = {},
) {
const [pId, rId, jobName] = [projectId, ref, name].map(encodeURIComponent);

if (stream) {
return RequestHelper.stream(
this,
`projects/${pId}/jobs/artifacts/${rId}/download?job=${jobName}`,
options,
);
}
const [pId, rId, name] = [projectId, ref, jobName].map(encodeURIComponent);
const method = stream ? 'stream' : 'get';

return RequestHelper.get(
return RequestHelper[method](
this,
`projects/${pId}/jobs/artifacts/${rId}/download?job=${jobName}`,
`projects/${pId}/jobs/artifacts/${rId}/download?job=${name}`,
options,
);
}
Expand Down
16 changes: 13 additions & 3 deletions packages/gitbeaker-core/src/services/MergeRequests.ts
Original file line number Diff line number Diff line change
Expand Up @@ -115,9 +115,9 @@ export class MergeRequests extends BaseService {
projectId,
groupId,
...options
}: ({ projectId: string | number } | { groupId: string | number }) &
}: ({ projectId?: string | number } | { groupId?: string | number }) &
AllMergeRequestsOptions &
PaginatedRequestOptions) {
PaginatedRequestOptions = {}) {
let url;

if (projectId) {
Expand Down Expand Up @@ -212,7 +212,11 @@ export class MergeRequests extends BaseService {
closesIssues(projectId: string | number, mergerequestIid: number, options?: Sudo) {
const [pId, mIid] = [projectId, mergerequestIid].map(encodeURIComponent);

return RequestHelper.get(this, `projects/${pId}/merge_requests/${mIid}/closes_issues`, options);
return RequestHelper.get(
this,
`projects/${pId}/merge_requests/${mIid}/closes_merge_requests`,
options,
);
}

commits(projectId: string | number, mergerequestIid: number, options?: Sudo) {
Expand Down Expand Up @@ -315,6 +319,12 @@ export class MergeRequests extends BaseService {
return RequestHelper.get(this, `projects/${pId}/merge_requests/${mIid}`, options);
}

subscribe(projectId: string | number, mergerequestIid: number, options?: Sudo) {
const [pId, mIid] = [projectId, mergerequestIid].map(encodeURIComponent);

return RequestHelper.post(this, `projects/${pId}/merge_requests/${mIid}/subscribe`, options);
}

timeStats(projectId: string | number, mergerequestIid: number, options?: Sudo) {
const [pId, mIid] = [projectId, mergerequestIid].map(encodeURIComponent);

Expand Down
38 changes: 15 additions & 23 deletions packages/gitbeaker-core/src/services/NotificationSettings.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import { formatQuery } from '@gitbeaker/requester-utils';
import {
BaseRequestOptions,
BaseService,
Expand All @@ -16,35 +15,28 @@ type NotificationSettingLevel =

type ProjectOrGroup = { projectId: string | number } | { groupId: string | number } | {};

export class NotificationSettings extends BaseService {
all({ projectId, groupId, sudo, ...query }: ProjectOrGroup & PaginatedRequestOptions = {}) {
const q = formatQuery(query);
let url = '';
function url({ projectId, groupId }) {
let uri = '';

if (projectId) {
uri += `projects/${encodeURIComponent(projectId)}/`;
} else if (groupId) {
uri += `groups/${encodeURIComponent(groupId)}/`;
}

if (projectId) {
url += `projects/${encodeURIComponent(projectId)}/`;
} else if (groupId) {
url += `groups/${encodeURIComponent(groupId)}/`;
}
return `${uri}notification_settings`;
}

return RequestHelper.get(this, `${url}notification_settings?${q}`, { sudo });
export class NotificationSettings extends BaseService {
all({ projectId, groupId, ...options }: ProjectOrGroup & PaginatedRequestOptions = {}) {
return RequestHelper.get(this, url({ groupId, projectId }), options);
}

edit({
projectId,
groupId,
sudo,
...query
...options
}: { level?: NotificationSettingLevel } & ProjectOrGroup & BaseRequestOptions = {}) {
const q = formatQuery(query);
let url = '';

if (projectId) {
url += `projects/${encodeURIComponent(projectId)}/`;
} else if (groupId) {
url += `groups/${encodeURIComponent(groupId)}/`;
}

return RequestHelper.put(this, `${url}notification_settings?${q}`, { sudo });
return RequestHelper.put(this, url({ groupId, projectId }), options);
}
}
Loading