@@ -52,72 +52,113 @@ describe("Deprecations", () => {
5252 expect ( warnCalledCount ) . toEqual ( 1 ) ;
5353 } ) ;
5454
55- // it("deprecated parameter", async () => {
56- // const mock = fetchMock
57- // .sandbox()
58- // .getOnce("path:/repos/octocat/hello-world/commits/sha123", {
59- // ok: true
60- // });
61- // const MyOctokit = Octokit.plugin(restEndpointMethods);
62- // let warnCalledCount = 0;
63- // const octokit = new MyOctokit({
64- // request: {
65- // fetch: mock
66- // },
67- // log: {
68- // warn: (deprecation: Error) => {
69- // warnCalledCount++;
70- // expect(deprecation).toMatch(
71- // '"commit_sha" parameter is deprecated for "octokit.repos.getCommit()". Use "ref" instead'
72- // );
73- // }
74- // }
75- // });
76- // // See https://developer.github.com/v3/issues/comments/#create-a-comment
77- // const { data } = await octokit.repos.getCommit({
78- // owner: "octocat",
79- // repo: "hello-world",
80- // commit_sha: "sha123"
81- // });
82- // expect(data).toStrictEqual({ ok: true });
83- // expect(warnCalledCount).toEqual(1);
84- // });
85- // it("deprecated parameter + new parameter", async () => {
86- // const mock = fetchMock.sandbox().post(
87- // "path:/repos/octocat/hello-world/issues/456/comments",
88- // {
89- // ok: true
90- // },
91- // {
92- // body: {
93- // body: "Hello there!"
94- // }
95- // }
96- // );
97- // const MyOctokit = Octokit.plugin(restEndpointMethods);
98- // let warnCalledCount = 0;
99- // const octokit = new MyOctokit({
100- // request: {
101- // fetch: mock
102- // },
103- // log: {
104- // warn: (deprecation: Error) => {
105- // warnCalledCount++;
106- // expect(deprecation).toMatch(
107- // '"number" parameter is deprecated for "octokit.issues.createComment()". Use "issue_number" instead'
108- // );
109- // }
110- // }
111- // });
112- // // See https://developer.github.com/v3/issues/comments/#create-a-comment
113- // const { data } = await octokit.issues.createComment({
114- // owner: "octocat",
115- // repo: "hello-world",
116- // number: 123,
117- // issue_number: 456,
118- // body: "Hello there!"
119- // });
120- // expect(data).toStrictEqual({ ok: true });
121- // expect(warnCalledCount).toEqual(1);
122- // });
55+ it ( "deprecated parameter" , async ( ) => {
56+ const mock = fetchMock
57+ . sandbox ( )
58+ . putOnce ( "path:/repos/octocat/hello-world/actions/secrets/MY_SECRET" , {
59+ ok : true ,
60+ } ) ;
61+ const MyOctokit = Octokit . plugin ( restEndpointMethods ) ;
62+
63+ let warnCalledCount = 0 ;
64+ const octokit = new MyOctokit ( {
65+ request : {
66+ fetch : mock ,
67+ } ,
68+ log : {
69+ warn : ( deprecation : Error ) => {
70+ warnCalledCount ++ ;
71+ expect ( deprecation ) . toMatch (
72+ '"name" parameter is deprecated for "octokit.actions.createOrUpdateRepoSecret()". Use "secret_name" instead'
73+ ) ;
74+ } ,
75+ } ,
76+ } ) ;
77+ // See https://developer.github.com/v3/actions/secrets/#create-or-update-a-repository-secret
78+ // The `:secret_name` URL parameter was `:name` until May 14, 2020
79+ // @ts -ignore
80+ const { data } = await octokit . actions . createOrUpdateRepoSecret ( {
81+ owner : "octocat" ,
82+ repo : "hello-world" ,
83+ name : "MY_SECRET" ,
84+ encrypted_value : "encrypted value 123" ,
85+ key_id : "key id 123" ,
86+ } ) ;
87+ expect ( data ) . toStrictEqual ( { ok : true } ) ;
88+ expect ( warnCalledCount ) . toEqual ( 1 ) ;
89+ } ) ;
90+
91+ it ( "deprecated parameter + new parameter" , async ( ) => {
92+ const mock = fetchMock
93+ . sandbox ( )
94+ . putOnce ( "path:/repos/octocat/hello-world/actions/secrets/MY_SECRET2" , {
95+ ok : true ,
96+ } ) ;
97+ const MyOctokit = Octokit . plugin ( restEndpointMethods ) ;
98+
99+ let warnCalledCount = 0 ;
100+ const octokit = new MyOctokit ( {
101+ request : {
102+ fetch : mock ,
103+ } ,
104+ log : {
105+ warn : ( deprecation : Error ) => {
106+ warnCalledCount ++ ;
107+ expect ( deprecation ) . toMatch (
108+ '"name" parameter is deprecated for "octokit.actions.createOrUpdateRepoSecret()". Use "secret_name" instead'
109+ ) ;
110+ } ,
111+ } ,
112+ } ) ;
113+ // See https://developer.github.com/v3/actions/secrets/#create-or-update-a-repository-secret
114+ // The `:secret_name` URL parameter was `:name` until May 14, 2020
115+ // @ts -ignore
116+ const { data } = await octokit . actions . createOrUpdateRepoSecret ( {
117+ owner : "octocat" ,
118+ repo : "hello-world" ,
119+ name : "MY_SECRET1" ,
120+ secret_name : "MY_SECRET2" ,
121+ encrypted_value : "encrypted value 123" ,
122+ key_id : "key id 123" ,
123+ } ) ;
124+ expect ( data ) . toStrictEqual ( { ok : true } ) ;
125+ expect ( warnCalledCount ) . toEqual ( 1 ) ;
126+ } ) ;
127+
128+ it ( "deprecated method + deprecated parameter" , async ( ) => {
129+ const mock = fetchMock
130+ . sandbox ( )
131+ . putOnce ( "path:/repos/octocat/hello-world/actions/secrets/MY_SECRET" , {
132+ ok : true ,
133+ } ) ;
134+ const MyOctokit = Octokit . plugin ( restEndpointMethods ) ;
135+
136+ const deprecations : string [ ] = [ ] ;
137+ const octokit = new MyOctokit ( {
138+ request : {
139+ fetch : mock ,
140+ } ,
141+ log : {
142+ warn : ( deprecation : Error ) => {
143+ deprecations . push ( deprecation . toString ( ) ) ;
144+ } ,
145+ } ,
146+ } ) ;
147+ // See https://developer.github.com/v3/actions/secrets/#create-or-update-a-repository-secret
148+ // The `:secret_name` URL parameter was `:name` until May 14, 2020
149+ // @ts -ignore
150+ const { data } = await octokit . actions . createOrUpdateSecretForRepo ( {
151+ owner : "octocat" ,
152+ repo : "hello-world" ,
153+ name : "MY_SECRET" ,
154+ encrypted_value : "encrypted value 123" ,
155+ key_id : "key id 123" ,
156+ } ) ;
157+ expect ( data ) . toStrictEqual ( { ok : true } ) ;
158+ expect ( deprecations . length ) . toEqual ( 2 ) ;
159+ expect ( deprecations . sort ( ) ) . toStrictEqual ( [
160+ '"name" parameter is deprecated for "octokit.actions.createOrUpdateSecretForRepo()". Use "secret_name" instead' ,
161+ "octokit.actions.createOrUpdateSecretForRepo() has been renamed to octokit.actions.createOrUpdateRepoSecret()" ,
162+ ] ) ;
163+ } ) ;
123164} ) ;
0 commit comments