Skip to content

Commit

Permalink
test(workspaces): add workspaces unit test
Browse files Browse the repository at this point in the history
  • Loading branch information
mijailr committed Oct 3, 2020
1 parent 1d78fa5 commit 3027cdc
Show file tree
Hide file tree
Showing 3 changed files with 84 additions and 0 deletions.
20 changes: 20 additions & 0 deletions test/api/Workspaces.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
import nock from 'nock'
import TerraformCloud from '../../src'
import { WorkspaceMock, WorkspaceNoVcsRequest } from '../mocks'
import { WorkspaceCreate } from '../../src/types'

const { Workspaces } = new TerraformCloud('api-key')
const organizationName = 'organization-name'

describe('Workspaces endpoints', () => {
it('create a workspace without VCS', async done => {
const scope = nock('https://app.terraform.io/api/v2')
.post(`/organizations/${organizationName}/worspaces`, WorkspaceNoVcsRequest)
.reply(201, WorkspaceMock)
const workspace = await Workspaces.create(organizationName, WorkspaceNoVcsRequest as WorkspaceCreate)

expect(workspace.type).toBe('workspaces')
scope.done()
done()
})
})
63 changes: 63 additions & 0 deletions test/mocks/WorkspaceMock.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
export const WorkspaceNoVcsRequest = {
data: {
attributes: {
name: 'workspace-1',
},
type: 'workspaces',
},
}

export const WorkspaceMock = {
data: {
id: 'ws-YnyXLq9fy38afEeb',
type: 'workspaces',
attributes: {
'auto-apply': false,
'allow-destroy-plan': false,
'can-queue-destroy-plan': false,
'created-at': '2017-11-18T00:43:59.384Z',
environment: 'default',
'file-triggers-enabled': true,
locked: false,
name: 'workspace-1',
permissions: {
'can-update': true,
'can-destroy': false,
'can-queue-destroy': false,
'can-queue-run': false,
'can-update-variable': false,
'can-lock': false,
'can-read-settings': true,
},
'queue-all-runs': false,
'terraform-version': '0.11.0',
'trigger-prefixes': [],
'vcs-repo': null,
'working-directory': '',
'execution-mode': 'agent',
},
relationships: {
organization: {
data: {
id: 'my-organization',
type: 'organizations',
},
},
'ssh-key': {
data: null,
},
'latest-run': {
data: null,
},
'agent-pool': {
data: {
id: 'apool-ZjT6A7mVFm5WHT5a',
type: 'agent-pools',
},
},
},
links: {
self: '/api/v2/organizations/my-organization/workspaces/workspace-1',
},
},
}
1 change: 1 addition & 0 deletions test/mocks/index.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
export * from './PlanMock'
export * from './RunMock'
export * from './UserMock'
export * from './WorkspaceMock'

0 comments on commit 3027cdc

Please sign in to comment.