@@ -79,66 +79,70 @@ describe('creation', () => {
79
79
} ) ;
80
80
} ) ;
81
81
82
- // describe('for organization', () => {
83
- // let getAuthenticated, listForAuthenticatedUser;
84
- //
85
- // beforeEach(() => {
86
- // getAuthenticated = vi.fn();
87
- // listForAuthenticatedUser = vi.fn();
88
- //
89
- // getAuthenticated.mockResolvedValue({data: {login: any.word()}});
90
- // listForAuthenticatedUser.mockResolvedValue({
91
- // data: [
92
- // ...any.listOf(() => ({...any.simpleObject(), login: any.word})),
93
- // {...any.simpleObject(), login: account}
94
- // ]
95
- // });
96
- // });
97
- //
98
- // // it('should create the repository for the provided organization account', async () => {
99
- // // const createInOrg = vi.fn();
100
- // // const get = vi.fn();
101
- // // const client = {repos: {createInOrg, get}, users: {getAuthenticated}, orgs: {listForAuthenticatedUser}};
102
- // // when(createInOrg).calledWith({org: account, name, private: false}).mockResolvedValue(repoDetailsResponse);
103
- // // get.mockImplementation(() => {
104
- // // throw repoNotFoundError;
105
- // // });
106
- // //
107
- // // expect(await scaffoldRepository(name, account, 'Public', client)).toEqual({sshUrl, htmlUrl});
108
- // // });
109
- //
110
- // // it('should not create the repository when it already exists', async () => {
111
- // // const createInOrg = vi.fn();
112
- // // const get = vi.fn();
113
- // // const client = {repos: {createInOrg, get}, users: {getAuthenticated}, orgs: {listForAuthenticatedUser}};
114
- // // when(get).calledWith({owner: account, repo: name}).mockResolvedValue(repoDetailsResponse);
115
- // //
116
- // // expect(await scaffoldRepository(name, account, 'Public', client)).toEqual({sshUrl, htmlUrl});
117
- // // expect(createInOrg).not.toHaveBeenCalled();
118
- // // });
119
- //
120
- // // it('should create the repository as private when visibility is `Private`', async () => {
121
- // // const createInOrg = vi.fn();
122
- // // const get = vi.fn();
123
- // // const client = {repos: {createInOrg, get}, users: {getAuthenticated}, orgs: {listForAuthenticatedUser}};
124
- // // when(createInOrg).calledWith({org: account, name, private: true}).mockResolvedValue(repoDetailsResponse);
125
- // // get.mockImplementation(() => {
126
- // // throw repoNotFoundError;
127
- // // });
128
- // //
129
- // // expect(await scaffoldRepository(name, account, 'Private', client)).toEqual({sshUrl, htmlUrl});
130
- // // });
131
- //
132
- // // it('should rethrow other errors', async () => {
133
- // // const get = vi.fn();
134
- // // const client = {repos: {get}, users: {getAuthenticated}, orgs: {listForAuthenticatedUser}};
135
- // // get.mockImplementation(() => {
136
- // // throw fetchFailureError;
137
- // // });
138
- // //
139
- // // await expect(scaffoldRepository(name, account, 'Private', client)).rejects.toThrowError(fetchFailureError);
140
- // // });
141
- // });
82
+ describe ( 'for organization' , ( ) => {
83
+ let getAuthenticated , listForAuthenticatedUser ;
84
+
85
+ beforeEach ( ( ) => {
86
+ getAuthenticated = vi . fn ( ) ;
87
+ listForAuthenticatedUser = vi . fn ( ) ;
88
+
89
+ getAuthenticated . mockResolvedValue ( { data : { login : any . word ( ) } } ) ;
90
+ listForAuthenticatedUser . mockResolvedValue ( {
91
+ data : [
92
+ ...any . listOf ( ( ) => ( { ...any . simpleObject ( ) , login : any . word } ) ) ,
93
+ { ...any . simpleObject ( ) , login : account }
94
+ ]
95
+ } ) ;
96
+ } ) ;
97
+
98
+ it ( 'should create the repository for the provided organization account' , async ( ) => {
99
+ const createInOrg = vi . fn ( ) ;
100
+ const get = vi . fn ( ) ;
101
+ const client = { repos : { createInOrg, get} , users : { getAuthenticated} , orgs : { listForAuthenticatedUser} } ;
102
+ when ( createInOrg ) . calledWith ( { org : account , name, private : false } ) . mockResolvedValue ( repoDetailsResponse ) ;
103
+ get . mockImplementation ( ( ) => {
104
+ throw repoNotFoundError ;
105
+ } ) ;
106
+
107
+ expect ( await scaffoldRepository ( { name, owner : account , visibility : 'Public' , octokit : client } ) )
108
+ . toEqual ( { sshUrl, htmlUrl} ) ;
109
+ } ) ;
110
+
111
+ it ( 'should not create the repository when it already exists' , async ( ) => {
112
+ const createInOrg = vi . fn ( ) ;
113
+ const get = vi . fn ( ) ;
114
+ const client = { repos : { createInOrg, get} , users : { getAuthenticated} , orgs : { listForAuthenticatedUser} } ;
115
+ when ( get ) . calledWith ( { owner : account , repo : name } ) . mockResolvedValue ( repoDetailsResponse ) ;
116
+
117
+ expect ( await scaffoldRepository ( { name, owner : account , visibility : 'Public' , octokit : client } ) )
118
+ . toEqual ( { sshUrl, htmlUrl} ) ;
119
+ expect ( createInOrg ) . not . toHaveBeenCalled ( ) ;
120
+ } ) ;
121
+
122
+ it ( 'should create the repository as private when visibility is `Private`' , async ( ) => {
123
+ const createInOrg = vi . fn ( ) ;
124
+ const get = vi . fn ( ) ;
125
+ const client = { repos : { createInOrg, get} , users : { getAuthenticated} , orgs : { listForAuthenticatedUser} } ;
126
+ when ( createInOrg ) . calledWith ( { org : account , name, private : true } ) . mockResolvedValue ( repoDetailsResponse ) ;
127
+ get . mockImplementation ( ( ) => {
128
+ throw repoNotFoundError ;
129
+ } ) ;
130
+
131
+ expect ( await scaffoldRepository ( { name, owner : account , visibility : 'Private' , octokit : client } ) )
132
+ . toEqual ( { sshUrl, htmlUrl} ) ;
133
+ } ) ;
134
+
135
+ it ( 'should rethrow other errors' , async ( ) => {
136
+ const get = vi . fn ( ) ;
137
+ const client = { repos : { get} , users : { getAuthenticated} , orgs : { listForAuthenticatedUser} } ;
138
+ get . mockImplementation ( ( ) => {
139
+ throw fetchFailureError ;
140
+ } ) ;
141
+
142
+ await expect ( scaffoldRepository ( { name, owner : account , visibility : 'Private' , octokit : client } ) )
143
+ . rejects . toThrowError ( fetchFailureError ) ;
144
+ } ) ;
145
+ } ) ;
142
146
143
147
describe ( 'unauthorized account' , ( ) => {
144
148
it ( 'should throw an error if the authenticated user does not have access to the requested account' , async ( ) => {
0 commit comments