Skip to content

Commit c915307

Browse files
api-clients-generation-pipeline[bot]ci.datadog-api-spec
andauthored
[OMG-1253] Add BDD test coverage for CreateTeamMembership (#3901)
Co-authored-by: ci.datadog-api-spec <packages@datadoghq.com>
1 parent 75a8916 commit c915307

6 files changed

Lines changed: 274 additions & 14 deletions

examples/v2/teams/CreateTeamMembership.go

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -13,21 +13,21 @@ import (
1313
)
1414

1515
func main() {
16+
// there is a valid "dd_team" in the system
17+
DdTeamDataID := os.Getenv("DD_TEAM_DATA_ID")
18+
19+
// there is a valid "user" in the system
20+
UserDataID := os.Getenv("USER_DATA_ID")
21+
1622
body := datadogV2.UserTeamRequest{
1723
Data: datadogV2.UserTeamCreate{
1824
Attributes: &datadogV2.UserTeamAttributes{
1925
Role: *datadogV2.NewNullableUserTeamRole(datadogV2.USERTEAMROLE_ADMIN.Ptr()),
2026
},
2127
Relationships: &datadogV2.UserTeamRelationships{
22-
Team: &datadogV2.RelationshipToUserTeamTeam{
23-
Data: datadogV2.RelationshipToUserTeamTeamData{
24-
Id: "d7e15d9d-d346-43da-81d8-3d9e71d9a5e9",
25-
Type: datadogV2.USERTEAMTEAMTYPE_TEAM,
26-
},
27-
},
2828
User: &datadogV2.RelationshipToUserTeamUser{
2929
Data: datadogV2.RelationshipToUserTeamUserData{
30-
Id: "b8626d7e-cedd-11eb-abf5-da7ad0900001",
30+
Id: UserDataID,
3131
Type: datadogV2.USERTEAMUSERTYPE_USERS,
3232
},
3333
},
@@ -39,7 +39,7 @@ func main() {
3939
configuration := datadog.NewConfiguration()
4040
apiClient := datadog.NewAPIClient(configuration)
4141
api := datadogV2.NewTeamsApi(apiClient)
42-
resp, r, err := api.CreateTeamMembership(ctx, "team_id", body)
42+
resp, r, err := api.CreateTeamMembership(ctx, DdTeamDataID, body)
4343

4444
if err != nil {
4545
fmt.Fprintf(os.Stderr, "Error when calling `TeamsApi.CreateTeamMembership`: %v\n", err)
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
2026-03-31T14:58:05.044Z
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,136 @@
1+
interactions:
2+
- request:
3+
body: |
4+
{"data":{"attributes":{"handle":"test-handle-22e42ce95626a92a","name":"test-name-22e42ce95626a92a"},"type":"team"}}
5+
form: {}
6+
headers:
7+
Accept:
8+
- application/json
9+
Content-Type:
10+
- application/json
11+
id: 0
12+
method: POST
13+
url: https://api.datadoghq.com/api/v2/team
14+
response:
15+
body: '{"data":{"id":"abc7c612-d3a1-4147-bcfa-f28b4af43d33","type":"team","attributes":{"avatar":null,"banner":10,"created_at":"2026-03-31T14:58:05.503733+00:00","description":null,"handle":"test-handle-22e42ce95626a92a","hidden_modules":null,"is_managed":false,"link_count":0,"modified_at":"2026-03-31T14:58:05.503733+00:00","name":"test-name-22e42ce95626a92a","summary":null,"user_count":0,"visible_modules":null},"relationships":{"team_links":{"data":[],"links":{"related":"/api/v2/team/abc7c612-d3a1-4147-bcfa-f28b4af43d33/links"}},"user_team_permissions":{"data":null,"links":{"related":"/api/v2/team/abc7c612-d3a1-4147-bcfa-f28b4af43d33/permission-settings"}}}}}'
16+
code: 201
17+
duration: 0ms
18+
headers:
19+
Content-Type:
20+
- application/vnd.api+json
21+
status: 201 Created
22+
- request:
23+
body: |
24+
{"data":{"attributes":{"email":"Test-Add_a_user_to_a_team_returns_API_error_response_response-1774969085@datadoghq.com","title":"user title"},"type":"users"}}
25+
form: {}
26+
headers:
27+
Accept:
28+
- application/json
29+
Content-Type:
30+
- application/json
31+
id: 1
32+
method: POST
33+
url: https://api.datadoghq.com/api/v2/users
34+
response:
35+
body: '{"data": {"type": "users", "id": "825c5f4c-585c-494a-aade-60f1e1aa189b",
36+
"attributes": {"name": null, "handle": "test-add_a_user_to_a_team_returns_api_error_response_response-1774969085@datadoghq.com",
37+
"created_at": "2026-03-31T14:58:06.030754+00:00", "modified_at": "2026-03-31T14:58:06.030754+00:00",
38+
"email": "test-add_a_user_to_a_team_returns_api_error_response_response-1774969085@datadoghq.com",
39+
"icon": "https://secure.gravatar.com/avatar/53ba6f826ef9a49acaeec55d1bcc1c47?s=48&d=retro",
40+
"title": "user title", "verified": false, "service_account": false, "disabled":
41+
false, "allowed_login_methods": [], "status": "Pending", "last_login_time":
42+
null}, "relationships": {"roles": {"data": []}, "org": {"data": {"type": "orgs",
43+
"id": "4dee724d-00cc-11ea-a77b-570c9d03c6c5"}}}}}'
44+
code: 201
45+
duration: 0ms
46+
headers:
47+
Content-Type:
48+
- application/json
49+
status: 201 Created
50+
- request:
51+
body: |
52+
{"data":{"attributes":{"role":"admin"},"relationships":{"user":{"data":{"id":"825c5f4c-585c-494a-aade-60f1e1aa189b","type":"users"}}},"type":"team_memberships"}}
53+
form: {}
54+
headers:
55+
Accept:
56+
- application/json
57+
Content-Type:
58+
- application/json
59+
id: 2
60+
method: POST
61+
url: https://api.datadoghq.com/api/v2/team/abc7c612-d3a1-4147-bcfa-f28b4af43d33/memberships
62+
response:
63+
body: '{"data":{"id":"TeamMembership-abc7c612-d3a1-4147-bcfa-f28b4af43d33-66215044","type":"team_memberships","attributes":{"provisioned_by":null,"provisioned_by_id":"a1d5ff5a-c6dd-11f0-9cb6-06640ca27ad4","role":"admin"},"relationships":{"user":{"data":{"id":"825c5f4c-585c-494a-aade-60f1e1aa189b","type":"users"}}}},"included":[{"id":"825c5f4c-585c-494a-aade-60f1e1aa189b","type":"users","attributes":{"disabled":false,"email":"test-add_a_user_to_a_team_returns_api_error_response_response-1774969085@datadoghq.com","handle":"test-add_a_user_to_a_team_returns_api_error_response_response-1774969085@datadoghq.com","icon":"https://secure.gravatar.com/avatar/53ba6f826ef9a49acaeec55d1bcc1c47?d=retro\u0026s=48","name":null,"service_account":false,"status":"Pending"}}]}'
64+
code: 200
65+
duration: 0ms
66+
headers:
67+
Content-Type:
68+
- application/vnd.api+json
69+
status: 200 OK
70+
- request:
71+
body: |
72+
{"data":{"attributes":{"role":"admin"},"relationships":{"user":{"data":{"id":"825c5f4c-585c-494a-aade-60f1e1aa189b","type":"users"}}},"type":"team_memberships"}}
73+
form: {}
74+
headers:
75+
Accept:
76+
- application/json
77+
Content-Type:
78+
- application/json
79+
id: 3
80+
method: POST
81+
url: https://api.datadoghq.com/api/v2/team/abc7c612-d3a1-4147-bcfa-f28b4af43d33/memberships
82+
response:
83+
body: '{"errors":[{"status":"409","title":"Conflict","detail":"users already present
84+
on the team [825c5f4c-585c-494a-aade-60f1e1aa189b]"}]}'
85+
code: 409
86+
duration: 0ms
87+
headers:
88+
Content-Type:
89+
- application/vnd.api+json
90+
status: 409 Conflict
91+
- request:
92+
body: ''
93+
form: {}
94+
headers:
95+
Accept:
96+
- '*/*'
97+
id: 4
98+
method: DELETE
99+
url: https://api.datadoghq.com/api/v2/team/abc7c612-d3a1-4147-bcfa-f28b4af43d33/memberships/825c5f4c-585c-494a-aade-60f1e1aa189b
100+
response:
101+
body: ''
102+
code: 204
103+
duration: 0ms
104+
headers: {}
105+
status: 204 No Content
106+
- request:
107+
body: ''
108+
form: {}
109+
headers:
110+
Accept:
111+
- '*/*'
112+
id: 5
113+
method: DELETE
114+
url: https://api.datadoghq.com/api/v2/users/825c5f4c-585c-494a-aade-60f1e1aa189b
115+
response:
116+
body: ''
117+
code: 204
118+
duration: 0ms
119+
headers: {}
120+
status: 204 No Content
121+
- request:
122+
body: ''
123+
form: {}
124+
headers:
125+
Accept:
126+
- '*/*'
127+
id: 6
128+
method: DELETE
129+
url: https://api.datadoghq.com/api/v2/team/abc7c612-d3a1-4147-bcfa-f28b4af43d33
130+
response:
131+
body: ''
132+
code: 204
133+
duration: 0ms
134+
headers: {}
135+
status: 204 No Content
136+
version: 2
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
2026-03-31T14:57:49.739Z
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,115 @@
1+
interactions:
2+
- request:
3+
body: |
4+
{"data":{"attributes":{"handle":"test-handle-3170c6f6f5b25b4d","name":"test-name-3170c6f6f5b25b4d"},"type":"team"}}
5+
form: {}
6+
headers:
7+
Accept:
8+
- application/json
9+
Content-Type:
10+
- application/json
11+
id: 0
12+
method: POST
13+
url: https://api.datadoghq.com/api/v2/team
14+
response:
15+
body: '{"data":{"id":"95ac9e78-0a56-4a6a-9e5e-21580dc141cc","type":"team","attributes":{"avatar":null,"banner":9,"created_at":"2026-03-31T14:57:54.888553+00:00","description":null,"handle":"test-handle-3170c6f6f5b25b4d","hidden_modules":null,"is_managed":false,"link_count":0,"modified_at":"2026-03-31T14:57:54.888553+00:00","name":"test-name-3170c6f6f5b25b4d","summary":null,"user_count":0,"visible_modules":null},"relationships":{"team_links":{"data":[],"links":{"related":"/api/v2/team/95ac9e78-0a56-4a6a-9e5e-21580dc141cc/links"}},"user_team_permissions":{"data":null,"links":{"related":"/api/v2/team/95ac9e78-0a56-4a6a-9e5e-21580dc141cc/permission-settings"}}}}}'
16+
code: 201
17+
duration: 0ms
18+
headers:
19+
Content-Type:
20+
- application/vnd.api+json
21+
status: 201 Created
22+
- request:
23+
body: |
24+
{"data":{"attributes":{"email":"Test-Add_a_user_to_a_team_returns_Represents_a_user_s_association_to_a_team_response-1774969069@datadoghq.com","title":"user title"},"type":"users"}}
25+
form: {}
26+
headers:
27+
Accept:
28+
- application/json
29+
Content-Type:
30+
- application/json
31+
id: 1
32+
method: POST
33+
url: https://api.datadoghq.com/api/v2/users
34+
response:
35+
body: '{"data": {"type": "users", "id": "ebb17d15-5e46-4440-856f-75710cbbce4b",
36+
"attributes": {"name": null, "handle": "test-add_a_user_to_a_team_returns_represents_a_user_s_association_to_a_team_response-1774969069@datadoghq.com",
37+
"created_at": "2026-03-31T14:57:55.106406+00:00", "modified_at": "2026-03-31T14:57:55.106406+00:00",
38+
"email": "test-add_a_user_to_a_team_returns_represents_a_user_s_association_to_a_team_response-1774969069@datadoghq.com",
39+
"icon": "https://secure.gravatar.com/avatar/52a30c814f85968a9d363cc103840284?s=48&d=retro",
40+
"title": "user title", "verified": false, "service_account": false, "disabled":
41+
false, "allowed_login_methods": [], "status": "Pending", "last_login_time":
42+
null}, "relationships": {"roles": {"data": []}, "org": {"data": {"type": "orgs",
43+
"id": "4dee724d-00cc-11ea-a77b-570c9d03c6c5"}}}}}'
44+
code: 201
45+
duration: 0ms
46+
headers:
47+
Content-Type:
48+
- application/json
49+
status: 201 Created
50+
- request:
51+
body: |
52+
{"data":{"attributes":{"role":"admin"},"relationships":{"user":{"data":{"id":"ebb17d15-5e46-4440-856f-75710cbbce4b","type":"users"}}},"type":"team_memberships"}}
53+
form: {}
54+
headers:
55+
Accept:
56+
- application/json
57+
Content-Type:
58+
- application/json
59+
id: 2
60+
method: POST
61+
url: https://api.datadoghq.com/api/v2/team/95ac9e78-0a56-4a6a-9e5e-21580dc141cc/memberships
62+
response:
63+
body: '{"data":{"id":"TeamMembership-95ac9e78-0a56-4a6a-9e5e-21580dc141cc-66215040","type":"team_memberships","attributes":{"provisioned_by":null,"provisioned_by_id":"a1d5ff5a-c6dd-11f0-9cb6-06640ca27ad4","role":"admin"},"relationships":{"user":{"data":{"id":"ebb17d15-5e46-4440-856f-75710cbbce4b","type":"users"}}}},"included":[{"id":"ebb17d15-5e46-4440-856f-75710cbbce4b","type":"users","attributes":{"disabled":false,"email":"test-add_a_user_to_a_team_returns_represents_a_user_s_association_to_a_team_response-1774969069@datadoghq.com","handle":"test-add_a_user_to_a_team_returns_represents_a_user_s_association_to_a_team_response-1774969069@datadoghq.com","icon":"https://secure.gravatar.com/avatar/52a30c814f85968a9d363cc103840284?d=retro\u0026s=48","name":null,"service_account":false,"status":"Pending"}}]}'
64+
code: 200
65+
duration: 0ms
66+
headers:
67+
Content-Type:
68+
- application/vnd.api+json
69+
status: 200 OK
70+
- request:
71+
body: ''
72+
form: {}
73+
headers:
74+
Accept:
75+
- '*/*'
76+
id: 3
77+
method: DELETE
78+
url: https://api.datadoghq.com/api/v2/team/95ac9e78-0a56-4a6a-9e5e-21580dc141cc/memberships/ebb17d15-5e46-4440-856f-75710cbbce4b
79+
response:
80+
body: ''
81+
code: 204
82+
duration: 0ms
83+
headers: {}
84+
status: 204 No Content
85+
- request:
86+
body: ''
87+
form: {}
88+
headers:
89+
Accept:
90+
- '*/*'
91+
id: 4
92+
method: DELETE
93+
url: https://api.datadoghq.com/api/v2/users/ebb17d15-5e46-4440-856f-75710cbbce4b
94+
response:
95+
body: ''
96+
code: 204
97+
duration: 0ms
98+
headers: {}
99+
status: 204 No Content
100+
- request:
101+
body: ''
102+
form: {}
103+
headers:
104+
Accept:
105+
- '*/*'
106+
id: 5
107+
method: DELETE
108+
url: https://api.datadoghq.com/api/v2/team/95ac9e78-0a56-4a6a-9e5e-21580dc141cc
109+
response:
110+
body: ''
111+
code: 204
112+
duration: 0ms
113+
headers: {}
114+
status: 204 No Content
115+
version: 2

tests/scenarios/features/v2/teams.feature

Lines changed: 13 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -27,21 +27,28 @@ Feature: Teams
2727
When the request is sent
2828
Then the response status is 204 Added
2929

30-
@generated @skip @team:DataDog/aaa-omg
30+
@team:DataDog/aaa-omg
3131
Scenario: Add a user to a team returns "API error response." response
3232
Given new "CreateTeamMembership" request
33-
And request contains "team_id" parameter from "REPLACE.ME"
34-
And body with value {"data": {"attributes": {"role": "admin"}, "relationships": {"team": {"data": {"id": "d7e15d9d-d346-43da-81d8-3d9e71d9a5e9", "type": "team"}}, "user": {"data": {"id": "b8626d7e-cedd-11eb-abf5-da7ad0900001", "type": "users"}}}, "type": "team_memberships"}}
33+
And there is a valid "dd_team" in the system
34+
And there is a valid "user" in the system
35+
And there is a valid "team_membership" in the system
36+
And request contains "team_id" parameter from "dd_team.data.id"
37+
And body with value {"data": {"attributes": {"role": "admin"}, "relationships": {"user": {"data": {"id": "{{user.data.id}}", "type": "users"}}}, "type": "team_memberships"}}
3538
When the request is sent
3639
Then the response status is 409 API error response.
3740

38-
@generated @skip @team:DataDog/aaa-omg
41+
@team:DataDog/aaa-omg
3942
Scenario: Add a user to a team returns "Represents a user's association to a team" response
4043
Given new "CreateTeamMembership" request
41-
And request contains "team_id" parameter from "REPLACE.ME"
42-
And body with value {"data": {"attributes": {"role": "admin"}, "relationships": {"team": {"data": {"id": "d7e15d9d-d346-43da-81d8-3d9e71d9a5e9", "type": "team"}}, "user": {"data": {"id": "b8626d7e-cedd-11eb-abf5-da7ad0900001", "type": "users"}}}, "type": "team_memberships"}}
44+
And there is a valid "dd_team" in the system
45+
And there is a valid "user" in the system
46+
And request contains "team_id" parameter from "dd_team.data.id"
47+
And body with value {"data": {"attributes": {"role": "admin"}, "relationships": {"user": {"data": {"id": "{{user.data.id}}", "type": "users"}}}, "type": "team_memberships"}}
4348
When the request is sent
4449
Then the response status is 200 Represents a user's association to a team
50+
And the response "data.attributes.role" is equal to "admin"
51+
And the response "data.relationships.user.data.id" is equal to "{{ user.data.id }}"
4552

4653
@team:DataDog/aaa-omg
4754
Scenario: Create a team hierarchy link returns "Conflict" response

0 commit comments

Comments
 (0)